0% found this document useful (0 votes)
8 views51 pages

Android Mobile Computing Lab Guide

A comprehensive list out all lab experiments in mobile computing (Computer science engineering)

Uploaded by

balasunilp0
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views51 pages

Android Mobile Computing Lab Guide

A comprehensive list out all lab experiments in mobile computing (Computer science engineering)

Uploaded by

balasunilp0
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

COMPUTER SCIENCE AND ENGINEERING

[Link] COLLEGE OF ENGINEERING


(Autonomous)
AFFILIATED TO ANNA UNIVERSITY CHENNAI

PERTINENT TO REGULATION 2018

18CSE026JL – MOBILE COMPUTING


LABORATORY

1
COMPUTER SCIENCE AND ENGINEERING

Ex No:1 ANDROID PLATFORM AND PROJECT STRUCTURE

ANDROID:
Android is an open source and Linux-based operating system for mobile devices such
as smart phones and tablet computers. Android was developed by the Open Handset Alliance,
led by Google, and other companies. It is a complete set of software for mobile devices such
as tablet computers, notebooks, smart phones, electronic book readers, set-top boxes etc.

It contains a Linux-based Operating System, middleware and key mobile applications.

It can be thought of as a mobile operating system. But it is not limited to mobile only.
It is currently used in various devices such as mobiles, tablets, televisions etc.

ANDROID ARCHITECTURE:

ANDROID APPLICATIONS:
Android applications are usually developed in the Java language using the Android
Software Development [Link] developed, Android applications can be packaged easily and
sold out either through a store such as Google Play, SlideME, Opera Mobile Store, Mobango,
F-droid and the Amazon Appstore.

2
COMPUTER SCIENCE AND ENGINEERING

Android powers hundreds of millions of mobile devices in more than 190 countries
around the world. It's the largest installed base of any mobile platform and growing fast.
Every day more than 1 million new Android devices are activated worldwide.

HISTORY OF ANDROID:
The code names of android ranges from A to N currently, such as Aestro, Blender,
Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream Sandwitch, Jelly Bean,
KitKat, Lollipop and Marshmallow

API LEVEL
API Level is an integer value that uniquely identifies the framework API revision
offered by a version of the Android platform.

LAYOUT
A layout describes the appearance of the screen. Layouts are written as XML files and
they tell Android how the different screen elements are arranged. A layout defines the
structure for a user interface in your app, such as in an activity. All elements in the layout are
built using a hierarchy of View and ViewGroup objects. A View usually draws something the
user can see and interact with. A layout may contain any type of widgets such as buttons,
labels, textboxes, and so on.

ACTIVITY
An activity is a single, defined thing that your user can do. You might have an activity
to compose an email, take a photo, or find a contact. Activities are usually associated with
one screen, and they’re written in Java. An activity is a single, focused thing that the user can
do. Almost all activities interact with the user, so the Activity class takes care of creating a
window for you in which you can place your UI with Activity. SetContentView(View).

RESOURCES
There are many more items which you use to build a good Android application. Apart
from coding for the application, you take care of various other resources like static content
that your code uses, such as bitmaps, colors, layout definitions, user interface strings,
animation instructions, and more. These resources are always maintained separately in
various sub-directories under res/ directory of the project

ANDROID VIRTUAL DEVICE

3
COMPUTER SCIENCE AND ENGINEERING

The Android emulator allows you to run your app on an Android virtual device
(AVD). The AVD behaves just like a physical Android device. You can set up numerous
AVDs, each emulating a different type of device.

The emulator is an application that re-creates the exact hardware environment of an


Android device: from its CPU and memory, through to the sound chips and the video display.
The emulator is built on an existing emulator called QEMU, which is similar to other virtual
machine applications you may have used, like Virtual Box or VMWare.

MANIFEST FILE
[Link] contains information about the app itself. It lives in the
app/src/main folder.

ANDROID SDK
The Android Software Development Kit contains the libraries and tools you need to
develop Androidapps

ANDROID STUDIO
Android Studio, includes all the tools you need to develop your [Link]
IDEA is one of the most popular IDEs for Java development. Android Studio is a version of
IDEA that includes a version of the Android SDK and extra GUI tools to help you with your
app development. Android Studio gives you templates you can use to help you create new
apps and classes, and it makes it easy to do things such as package your apps and run them.

ANDROID RUNTIME
Code doesn’t actually run inside an ordinary Java VM. It runs on the Android runtime
(ART)instead, and on older devices it runs in a predecessor to ART called Dalvik. This
means that you write your Java source code, compile it into .class files using the Java
compiler, and then the .class files get stitched into a single file in DEX format, which is
smaller, more efficient byte code. ART then runs the DEX code. ART can convert the DEX
byte code into native code that can run directly on the CPU of the Android device. This
makes the app run a lot faster, and use a lot less battery power.

CONCLUSION
Thus the study of Android Platform and Project Structure is learned and understand
successfully.

4
COMPUTER SCIENCE AND ENGINEERING

Ex No:2 DEVELOPING A SIMPLE ANDROID APPLICATION

OBJECTIVE OF THE EXPERIMENT


To develop an Android Native Calculator application using android studio.

PROCEDURE
1. Open Android Studio and then click on File -> New -> New project.
2. Then type the Application name and click Next.
3. Then select the Minimum SDK and click Next.
4. Then select the Empty Activity and click Next.
5. Finally click Finish.
6. Click on app -> res -> layout -> activity_main.xml and edit it
7. Click on app -> java -> [Link] -> [Link] and edit it
8. Start the Android Virtual Device
9. Click on run button to start the application in AVD

PROGARAM:
Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
android:id="@+id/ll1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"

5
COMPUTER SCIENCE AND ENGINEERING

android:orientation="horizontal">

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:ems="5"
android:inputType="number"
android:textSize="20sp" />

<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:ems="5"
android:inputType="number"
android:textSize="20sp" />
</LinearLayout>

<LinearLayout
android:id="@+id/ll2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="167dp"
android:orientation="horizontal">

6
COMPUTER SCIENCE AND ENGINEERING

<Button
android:id="@+id/btnAdd"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:onClick="Add"
android:text="+"
android:textSize="30sp" />

<Button
android:id="@+id/btnSub"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:onClick="Substract"
android:text="-"
android:textSize="30sp" />

<Button
android:id="@+id/btnMul"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:onClick="Multiply"
android:text="*"
android:textSize="30sp" />

<Button

7
COMPUTER SCIENCE AND ENGINEERING

android:id="@+id/btnDiv"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:text="/"
android:textSize="30sp" />
</LinearLayout>

<TextView
android:id="@+id/resultText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="180dp"
android:text="Answer is"
android:textSize="35sp" />
</RelativeLayout>

Activity:

package [Link].ex1nativecalc;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


EditText editTextN1;
EditText editTextN2;
Button buttonDiv;
TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {

8
COMPUTER SCIENCE AND ENGINEERING

[Link](savedInstanceState);
setContentView([Link].activity_main);
buttonDiv = findViewById([Link]);
result = findViewById([Link]);
editTextN1 = findViewById([Link].editText1);
editTextN2 = findViewById([Link].editText2);

[Link] ocl = new [Link]() {


@Override
public void onClick(View v) {
if([Link]([Link]().toString()) ||
[Link]([Link]().toString()))
return;
float div;
String n1 = [Link]().toString();
int num1 = [Link](n1);
String n2 = [Link]().toString();
int num2 = [Link](n2);
div = (float)num1 / (float)num2;
[Link](num1+" / "+num2+" = "+div);
}
};
[Link](ocl);
}

public void Add(View view){


if([Link]([Link]().toString()) ||
[Link]([Link]().toString()))
return;
int sum;
String n1 = [Link]().toString();
int num1 = [Link](n1);
String n2 = [Link]().toString();
int num2 = [Link](n2);
sum = num1 + num2;
[Link](num1+" + "+num2+" = "+sum);
}

public void Substract(View view){


if([Link]([Link]().toString()) ||
[Link]([Link]().toString()))
return;
int sub;
String n1 = [Link]().toString();
int num1 = [Link](n1);
String n2 = [Link]().toString();
int num2 = [Link](n2);
sub = num1 - num2;
[Link](num1+" - "+num2+" = "+sub);

9
COMPUTER SCIENCE AND ENGINEERING

public void Multiply(View view){


if([Link]([Link]().toString()) ||
[Link]([Link]().toString()))
return;
int mul;
String n1 = [Link]().toString();
int num1 = [Link](n1);
String n2 = [Link]().toString();
int num2 = [Link](n2);
mul = num1 * num2;
[Link](num1+" * "+num2+" = "+mul);
}

10
COMPUTER SCIENCE AND ENGINEERING

SAMPLE OUTPUT

CONCLUSION

11
COMPUTER SCIENCE AND ENGINEERING

Thus the android application is developed and executed using android studio
successfully.

Ex No: 3 CREATING APPLICATIONS WITH MULTIPLE ACTIVITIES AND A


SIMPLE MENU USING LISTVIEW

OBJECTIVE OF THE EXPERIMENT


To develop an Android Application with multiple activities and simple menu using list view.

PROCEDURE
1. Open Android Studio and then click on File -> New -> New project.
2. Then type the Application name and click Next.
3. Then select the Minimum SDK and click Next.
4. Then select the Empty Activity and click Next.
5. Finally click Finish.
6. Click on app -> res -> layout -> activity_main.xml and edit it
7. Click on app -> java -> [Link] -> [Link] and edit it
8. Start the Android Virtual Device
9. Click on run button to start the application in AVD

PROGARAM:
Layout:

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<ListView
android:id="@+id/lview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

12
COMPUTER SCIENCE AND ENGINEERING

activity_list.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/listLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ListActivity">

<TextView
android:id="@+id/textViewList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="40sp" />
</LinearLayout>

activity_second.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SecondActivity">

<ImageView
android:id="@+id/imageViewFlag"
android:layout_width="172dp"
android:layout_height="159dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="24dp"
android:layout_marginTop="18dp"
android:src="@drawable/india" />

<TextView

13
COMPUTER SCIENCE AND ENGINEERING

android:id="@+id/textViewCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="38dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="20dp"
android:text="@string/India"
android:textSize="20sp" />
</LinearLayout>

[Link]

<resources>
<string name="app_name">Ex2ListViewFlags</string>
<string-array name="options">
<item>India</item>
<item>England</item>
<item>China</item>
</string-array>
<string name="India">The National Flag of India is a horizontal rectangular tricolour of
India saffron, white and India green; with the Ashoka Chakra, a 24-spoke wheel, in navy blue
at its centre
</string>
<string name="China">The flag of China, also known as the Five-star Red Flag, is a red field
charged in the canton (upper corner nearest the flagpole) with five golden stars.</string>
<string name="Japan">The Nisshōki flag is designated as the national flag in the Law
Regarding the National Flag and National Anthem, which was promulgated and became
effective on August 13, 1999.</string>
<string name="America">It consists of thirteen equal horizontal stripes of red (top and
bottom) alternating with white, with a blue rectangle in the canton (referred to specifically as
the "union") bearing fifty small, white, five-pointed stars arranged in nine offset horizontal
rows, where rows of six stars (top and bottom) alternate with rows of five stars.</string>
<string name="Brazil">The flag of Brazil (Portuguese: Bandeira do Brasil), known in
Portuguese as A Auriverde (The Yellow-and-green One), is a blue disc depicting a starry sky
(which includes the Southern Cross) spanned by a curved band inscribed with the national
motto "Ordem e Progresso" ("Order and Progress"), within a yellow rhombus, on a green
field</string>
</resources>

Activity:

[Link]

14
COMPUTER SCIENCE AND ENGINEERING

package [Link].ex2listviewflags;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


ListView lv;
String[] countries = {"India","China","Japan","America","Brazil"};
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
lv = findViewById([Link]);
ArrayAdapter<String> arrayAdapter;
arrayAdapter = new ArrayAdapter<String>(this,
[Link].activity_list,[Link],countries);
[Link](arrayAdapter);
[Link] ocl = new [Link]() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent([Link],[Link]);
[Link]("index",id+"");
startActivity(intent);
}
};
[Link](ocl);
}
}

[Link]

package [Link].ex2listviewflags;

import [Link];
import [Link];
import [Link];
import [Link];

15
COMPUTER SCIENCE AND ENGINEERING

import [Link];

public class SecondActivity extends AppCompatActivity {


TextView textView;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_second);
textView = findViewById([Link]);
imageView = findViewById([Link]);
Intent intent = getIntent();
int i = [Link]([Link]("index"));
switch (i){
case 0:
[Link]([Link]);
[Link]([Link]);
break;
case 1:
[Link]([Link]);
[Link]([Link]);
break;
case 2:
[Link]([Link]);
[Link]([Link]);
break;
case 3:
[Link]([Link]);
[Link]([Link]);
break;
case 4:
[Link]([Link]);
[Link]([Link]);
break;
default:
[Link]("hello");
}
}
}

16
COMPUTER SCIENCE AND ENGINEERING

SAMPLE OUTPUT

17
COMPUTER SCIENCE AND ENGINEERING

CONCLUSION
Thus the android application is developed and executed using android studio
successfully.
EX NO:4 DEVELOPING AN APPLICATION WITH THE SUPPORT OF
ACTIVITY LIFECYCLE

OBJECTIVE OF THE EXPERIMENT


To develop an Android Application to implement activity lifecycle.

PROCEDURE
1. Open Android Studio and then click on File -> New -> New project.
2. Then type the Application name and click Next.
3. Then select the Minimum SDK and click Next.
4. Then select the Empty Activity and click Next.
5. Finally click Finish.
6. Click on app -> res -> layout -> activity_main.xml and edit it
7. Click on app -> java -> [Link] -> [Link] and edit it
8. Start the Android Virtual Device
9. Click on run button to start the application in AVD

PROGARAM:
Layout:

activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="[Link]">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"

18
COMPUTER SCIENCE AND ENGINEERING

app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>
Activity:
[Link]
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
Log.d("lifecycle","onCreate invoked");
}
@Override
protected void onStart() {
[Link]();
Log.d("lifecycle","onStart invoked");
}
@Override
protected void onResume() {
[Link]();
Log.d("lifecycle","onResume invoked");
}
@Override
protected void onPause() {
[Link]();
Log.d("lifecycle","onPause invoked");
}
@Override
protected void onStop() {
[Link]();
Log.d("lifecycle","onStop invoked");
}
@Override
protected void onRestart() {
[Link]();
Log.d("lifecycle","onRestart invoked");
}
@Override
protected void onDestroy() {

19
COMPUTER SCIENCE AND ENGINEERING

[Link]();
Log.d("lifecycle","onDestroy invoked");
}
}

SAMPLE OUTPUT

CONCLUSION

20
COMPUTER SCIENCE AND ENGINEERING

Thus the android application is developed and executed using android studio
successfully.
EX NO:5 WRITE AN APPLICATION THAT USES SQLITE DATABASES

OBJECTIVE OF THE EXPERIMENT


To develop an Android Application that makes use of SQLite databases.

PROCEDURE
1. Open Android Studio and then click on File -> New -> New project.
2. Then type the Application name and click Next.
3. Then select the Minimum SDK and click Next.
4. Then select the Empty Activity and click Next.
5. Finally click Finish.
6. Click on app -> res -> layout -> activity_main.xml and edit it
7. Click on app -> java -> [Link] -> [Link] and edit it
8. Start the Android Virtual Device
9. Click on run button to start the application in AVD

PROGARAM:
Layout:

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>


<AbsoluteLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="50dp"
android:layout_y="20dp"
android:text="Student Details"
android:textSize="30sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"

21
COMPUTER SCIENCE AND ENGINEERING

android:layout_y="110dp"
android:text="Enter Rollno:"
android:textSize="20sp" />

<EditText
android:id="@+id/Rollno"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="100dp"
android:inputType="number"
android:textSize="20sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="160dp"
android:text="Enter Name:"
android:textSize="20sp" />

<EditText
android:id="@+id/Name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="150dp"
android:inputType="text"
android:textSize="20sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="210dp"
android:text="Enter Marks:"
android:textSize="20sp" />

<EditText
android:id="@+id/Marks"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"

22
COMPUTER SCIENCE AND ENGINEERING

android:layout_y="200dp"
android:inputType="number"
android:textSize="20sp" />
<Button
android:id="@+id/Insert"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="300dp"
android:text="Insert"
android:textSize="30dp" />

<Button
android:id="@+id/Delete"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="300dp"
android:text="Delete"
android:textSize="30dp" />

<Button
android:id="@+id/Update"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="400dp"
android:text="Update"
android:textSize="30dp" />

<Button
android:id="@+id/View"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="400dp"
android:text="View"
android:textSize="30dp" />

<Button
android:id="@+id/ViewAll"
android:layout_width="200dp"
android:layout_height="wrap_content"

23
COMPUTER SCIENCE AND ENGINEERING

android:layout_x="100dp"
android:layout_y="500dp"
android:text="View All"
android:textSize="30dp" />

</AbsoluteLayout>

Activity:

[Link]

package [Link].exno5;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends Activity implements OnClickListener


{
EditText Rollno,Name,Marks;
Button Insert,Delete,Update,View,ViewAll;
SQLiteDatabase db;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);

Rollno=(EditText)findViewById([Link]);
Name=(EditText)findViewById([Link]);
Marks=(EditText)findViewById([Link]);
Insert=(Button)findViewById([Link]);
Delete=(Button)findViewById([Link]);
Update=(Button)findViewById([Link]);
View=(Button)findViewById([Link]);

24
COMPUTER SCIENCE AND ENGINEERING

ViewAll=(Button)findViewById([Link]);

[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);

// Creating database and table


db=openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
[Link]("CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,name
VARCHAR,marks VARCHAR);");
}
public void onClick(View view)
{
// Inserting a record to the Student table
if(view==Insert)
{
// Checking for empty fields
if([Link]().toString().trim().length()==0||
[Link]().toString().trim().length()==0||
[Link]().toString().trim().length()==0)
{
showMessage("Error", "Please enter all values");
return;
}
[Link]("INSERT INTO student VALUES('"+[Link]()+"','"+[Link]()+
"','"+[Link]()+"');");
showMessage("Success", "Record added");
clearText();
}
// Deleting a record from the Student table
if(view==Delete)
{
// Checking for empty roll number
if([Link]().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=[Link]("SELECT * FROM student WHERE
rollno='"+[Link]()+"'", null);
if([Link]())

25
COMPUTER SCIENCE AND ENGINEERING

{
[Link]("DELETE FROM student WHERE rollno='"+[Link]()+"'");
showMessage("Success", "Record Deleted");
}
else
{
showMessage("Error", "Invalid Rollno");
}
clearText();
}
// Updating a record in the Student table
if(view==Update)
{
// Checking for empty roll number
if([Link]().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=[Link]("SELECT * FROM student WHERE
rollno='"+[Link]()+"'", null);
if([Link]()) {
[Link]("UPDATE student SET name='" + [Link]() + "',marks='" +
[Link]() +
"' WHERE rollno='"+[Link]()+"'");
showMessage("Success", "Record Modified");
}
else {
showMessage("Error", "Invalid Rollno");
}
clearText();
}
// Display a record from the Student table
if(view==View)
{
// Checking for empty roll number
if([Link]().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=[Link]("SELECT * FROM student WHERE
rollno='"+[Link]()+"'", null);

26
COMPUTER SCIENCE AND ENGINEERING

if([Link]())
{
[Link]([Link](1));
[Link]([Link](2));
}
else
{
showMessage("Error", "Invalid Rollno");
clearText();
}
}
// Displaying all the records
if(view==ViewAll)
{
Cursor c=[Link]("SELECT * FROM student", null);
if([Link]()==0)
{
showMessage("Error", "No records found");
return;
}
StringBuffer buffer=new StringBuffer();
while([Link]())
{
[Link]("Rollno: "+[Link](0)+"\n");
[Link]("Name: "+[Link](1)+"\n");
[Link]("Marks: "+[Link](2)+"\n\n");
}
showMessage("Student Details", [Link]());
}
}
public void showMessage(String title,String message)
{
Builder builder=new Builder(this);
[Link](true);
[Link](title);
[Link](message);
[Link]();
}
public void clearText()
{
[Link]("");
[Link]("");
[Link]("");

27
COMPUTER SCIENCE AND ENGINEERING

[Link]();
}
}

SAMPLE OUTPUT

CONCLUSION
Thus the android application is developed and executed using android studio
successfully.

28
COMPUTER SCIENCE AND ENGINEERING

EX NO:6 CREATING ACTIVITY FOR PARSING THE XML FILE

OBJECTIVE OF THE EXPERIMENT


To develop an Android Application that makes use of RSS Feed.

PROCEDURE
1. Open Android Studio and then click on File -> New -> New project.
2. Then type the Application name and click Next.
3. Then select the Minimum SDK and click Next.
4. Then select the Empty Activity and click Next.
5. Finally click Finish.
6. Click on app -> res -> layout -> activity_main.xml and edit it
7. Click on app -> java -> [Link] -> [Link] and edit it
8. Start the Android Virtual Device
9. Click on run button to start the application in AVD

PROGARAM:
Layout:

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

[Link]:

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="[Link]
package="[Link].exno6" >

29
COMPUTER SCIENCE AND ENGINEERING

<uses-permission android:name="[Link]"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]" />


</intent-filter>
</activity>
</application>

</manifest>

Activity:

[Link]

package [Link].exno6;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

30
COMPUTER SCIENCE AND ENGINEERING

public class MainActivity extends ListActivity


{
List headlines;
List links;

@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
new MyAsyncTask().execute();
}

class MyAsyncTask extends AsyncTask<Object,Void,ArrayAdapter>


{
@Override
protected ArrayAdapter doInBackground(Object[] params)
{
headlines = new ArrayList();
links = new ArrayList();
try
{
URL url = new URL("[Link]
XmlPullParserFactory factory = [Link]();
[Link](false);
XmlPullParser xpp = [Link]();

// We will get the XML from an input stream


[Link](getInputStream(url), "UTF_8");
boolean insideItem = false;

// Returns the type of current event: START_TAG, END_TAG, etc..


int eventType = [Link]();
while (eventType != XmlPullParser.END_DOCUMENT)
{
if (eventType == XmlPullParser.START_TAG)
{
if ([Link]().equalsIgnoreCase("item"))
{
insideItem = true;
}
else if ([Link]().equalsIgnoreCase("title"))
{
if (insideItem)

31
COMPUTER SCIENCE AND ENGINEERING

[Link]([Link]()); //extract the headline


}
else if ([Link]().equalsIgnoreCase("link"))
{
if (insideItem)
[Link]([Link]()); //extract the link of article
}
}
else if(eventType==XmlPullParser.END_TAG &&
[Link]().equalsIgnoreCase("item"))
{
insideItem=false;
}
eventType = [Link](); //move to next element
}

}
catch (MalformedURLException e)
{
[Link]();
}
catch (XmlPullParserException e)
{
[Link]();
}
catch (IOException e)
{
[Link]();
}
return null;
}
protected void onPostExecute(ArrayAdapter adapter)
{
adapter = new ArrayAdapter([Link], [Link].simple_list_item_1,
headlines);
setListAdapter(adapter);
}
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
Uri uri = [Link](([Link](position)).toString());

32
COMPUTER SCIENCE AND ENGINEERING

Intent intent = new Intent(Intent.ACTION_VIEW, uri);


startActivity(intent);
}

public InputStream getInputStream(URL url)


{
try
{
return [Link]().getInputStream();
}
catch (IOException e)
{
return null;
}
}
}

33
COMPUTER SCIENCE AND ENGINEERING

SAMPLE OUTPUT

CONCLUSION
Thus the android application is developed and executed using android studio
successfully.
EX NO:7 WRITE AN APPLICATION TO IMPLEMENT FRAGMENT

34
COMPUTER SCIENCE AND ENGINEERING

OBJECTIVE OF THE EXPERIMENT


To develop an Android Application that makes use of fragment.

PROCEDURE
1. Open Android Studio and then click on File -> New -> New project.
2. Then type the Application name and click Next.
3. Then select the Minimum SDK and click Next.
4. Then select the Empty Activity and click Next.
5. Finally click Finish.
6. Click on app -> res -> layout -> activity_main.xml and edit it
7. Click on app -> java -> [Link] -> [Link] and edit it
8. Start the Android Virtual Device
9. Click on run button to start the application in AVD

PROGARAM:

Layout:
activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Fragment No.1"
android:onClick="selectFrag" />

<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="selectFrag"
android:text="Fragment No.2" />

<fragment
android:name="[Link]"

35
COMPUTER SCIENCE AND ENGINEERING

android:id="@+id/fragment_place"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

fragment_one.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#00ffff">

<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="This is fragment No.1"
android:textStyle="bold" />

</LinearLayout>

fragment_two.xml:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffff00">

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is fragment No.2"
android:textStyle="bold" />

</LinearLayout>

36
COMPUTER SCIENCE AND ENGINEERING

Activity:

[Link]:

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class FragmentOne extends Fragment {


@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {

//Inflate the layout for this fragment

return [Link](
[Link].fragment_one, container, false);
}
}

[Link]:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class FragmentTwo extends Fragment{


@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {

// Inflate the layout for this fragment

37
COMPUTER SCIENCE AND ENGINEERING

return [Link](
[Link].fragment_two, container, false);
}
}

[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
public void selectFrag(View view) {
Fragment fr;
if(view == findViewById([Link].button2)) {
fr = new FragmentTwo();
}else {
fr = new FragmentOne();
}
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = [Link]();
[Link]([Link].fragment_place, fr);
[Link]();
}
}

SAMPLE OUTPUT

38
COMPUTER SCIENCE AND ENGINEERING

CONCLUSION
Thus the android application is developed and executed using android studio
successfully.
EX NO:8 DEVELOP AN ANDROID APPLICATION THAT MAKES USE OF GPS

OBJECTIVE OF THE EXPERIMENT


To develop an Android Application that makes use of GPS.

39
COMPUTER SCIENCE AND ENGINEERING

PROCEDURE
1. Open Android Studio and then click on File -> New -> New project.
2. Then type the Application name and click Next.
3. Then select the Minimum SDK and click Next.
4. Then select the Empty Activity and click Next.
5. Finally click Finish.
6. Click on app -> res -> layout -> activity_main.xml and edit it
7. Click on app -> java -> [Link] -> [Link] and edit it
8. Start the Android Virtual Device
9. Click on run button to start the application in AVD

PROGARAM:
Layout:
activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="[Link]">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Latitude:"
android:textSize="24sp" />
<TextView
android:id="@+id/textlat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp" />
<TextView

40
COMPUTER SCIENCE AND ENGINEERING

android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Longitude:"
android:textSize="24sp" />
<TextView
android:id="@+id/textLong"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp" />
</LinearLayout>
</RelativeLayout>

[Link]:

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="[Link]
package="[Link]">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="[Link]"/>
<uses-permission android:name="[Link].ACCESS_FINE_LOCATION"/>
<uses-permission android:name="[Link].ACCESS_COARSE_LOCATION"/>
</manifest>

Activity:

[Link]
package [Link];

41
COMPUTER SCIENCE AND ENGINEERING

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity implements LocationListener {
LocationManager lmanager;
String provider;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
lmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = [Link](criteria, false);
// if ([Link].SDK_INT>=23 &&
[Link](this,[Link].ACCESS_FINE_LO
CATION)!= PackageManager.PERMISSION_GRANTED &&
[Link](this,[Link].ACCESS_COARSE
_LOCATION)!= PackageManager.PERMISSION_GRANTED)
// {
// return; //use this condition for AppCompatActivity
// }
if (provider != null && ![Link]("")) {
if ([Link].SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission([Link].ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
checkSelfPermission([Link].ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// Activity#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for Activity#requestPermissions for more details.

42
COMPUTER SCIENCE AND ENGINEERING

return;
}
}
Location location = [Link](provider);
[Link](provider,2000,1,this);
if (location!=null)
{
onLocationChanged(location);
}
else
{
[Link](getBaseContext(),"Location not available",Toast.LENGTH_LONG).show();
}
}
else
{
[Link](getBaseContext(),"No Provider Found",Toast.LENGTH_LONG).show();
}
}
@Override
public void onLocationChanged(Location location) {
TextView tv1 = (TextView) findViewById([Link]);
TextView tv2 = (TextView) findViewById([Link]);
[Link](""+[Link]());
[Link](""+[Link]());
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}

SAMPLE OUTPUT

43
COMPUTER SCIENCE AND ENGINEERING

CONCLUSION
Thus the android application is developed and executed using android studio
successfully.

EX NO:9 MEDIA AND CAMERA API

OBJECTIVE OF THE EXPERIMENT


To develop an Android Application that makes use of media and camera API.

44
COMPUTER SCIENCE AND ENGINEERING

PROCEDURE
1. Open Android Studio and then click on File -> New -> New project.
2. Then type the Application name and click Next.
3. Then select the Minimum SDK and click Next.
4. Then select the Empty Activity and click Next.
5. Finally click Finish.
6. Click on app -> res -> layout -> activity_main.xml and edit it
7. Click on app -> java -> [Link] -> [Link] and edit it
8. Start the Android Virtual Device
9. Click on run button to start the application in AVD

PROGARAM:
Layout:
activity_main.xml:

<RelativeLayout xmlns:androclass="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Take a Photo" >
</Button>

<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"

45
COMPUTER SCIENCE AND ENGINEERING

android:layout_height="fill_parent"
android:layout_above="@+id/button1"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" >
</ImageView>
</RelativeLayout>

Activity:

[Link]
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends Activity {


private static final int CAMERA_REQUEST = 1888;
ImageView imageView;
public void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);
setContentView([Link].activity_main);

imageView = (ImageView) [Link]([Link].imageView1);


Button photoButton = (Button) [Link]([Link].button1);

[Link](new [Link]() {

46
COMPUTER SCIENCE AND ENGINEERING

@Override
public void onClick(View v) {
Intent cameraIntent = new
Intent([Link].ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) [Link]().get("data");
[Link](photo);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link].activity_main, menu);
return true;
}

SAMPLE OUTPUT

47
COMPUTER SCIENCE AND ENGINEERING

CONCLUSION
Thus the android application is developed and executed using android studio
successfully.
EX NO:10 SENSOR PROGRAMMING

OBJECTIVE OF THE EXPERIMENT


To develop an Android Application that makes use of accelerometer.

PROCEDURE

48
COMPUTER SCIENCE AND ENGINEERING

1. Open Android Studio and then click on File -> New -> New project.
2. Then type the Application name and click Next.
3. Then select the Minimum SDK and click Next.
4. Then select the Empty Activity and click Next.
5. Finally click Finish.
6. Click on app -> res -> layout -> activity_main.xml and edit it
7. Click on app -> java -> [Link] -> [Link] and edit it
8. Start the Android Virtual Device
9. Click on run button to start the application in AVD

PROGARAM:
Layout:
activity_main.xml:

<RelativeLayout xmlns:androclass="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="92dp"
android:layout_marginTop="114dp"
android:text="TextView" />
</RelativeLayout>

Activity:
[Link]

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

49
COMPUTER SCIENCE AND ENGINEERING

import [Link];
import [Link];
public class MainActivity extends Activity {
SensorManager sm = null;
TextView textView1 = null;
List list;
SensorEventListener sel = new SensorEventListener(){
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
public void onSensorChanged(SensorEvent event) {
float[] values = [Link];
[Link]("x: "+values[0]+"\ny: "+values[1]+"\nz: "+values[2]);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

/* Get a SensorManager instance */


sm = (SensorManager)getSystemService(SENSOR_SERVICE);
textView1 = (TextView)findViewById([Link].textView1);
list = [Link](Sensor.TYPE_ACCELEROMETER);
if([Link]()>0){
[Link](sel, (Sensor) [Link](0), SensorManager.SENSOR_DELAY_NORMAL);
}else{
[Link](getBaseContext(), "Error: No Accelerometer.",
Toast.LENGTH_LONG).show();
}
}
@Override
protected void onStop() {
if([Link]()>0){
[Link](sel);
}
[Link]();
}
}

SAMPLE OUTPUT

50
COMPUTER SCIENCE AND ENGINEERING

CONCLUSION
Thus the android application is developed and executed using android studio
successfully.

51

You might also like