CS8662 - Mobile Application Development Lab Manual
CS8662 - Mobile Application Development Lab Manual
LAB MANUAL
Regulation : 2017
Branch : B.E., (CSE)
Year & Semester : III Year / VI Semester
AFFILIATED INSTITUTIONS
REGULATIONS – 2017
CHOICE BASED CREDIT SYSTEM
CS8662 – MOBILE APPLICATION DEVELOPMENT LABORATORY
LIST OF EXPERIMENTS
1. Develop an application that uses GUI components, Font and Colours.
2. Develop an application that uses Layout managers and event Handlers.
3. Write an application that draws basic graphical primitives on the screen.
4. Develop an application that makes use of Database.
5. Develop an application that makes use of Notification manager.
6. Implement an application that uses Multi – threading.
7. Develop a native application that uses GPS location information.
8. Implement an application that writes data to the SD card.
9. Implement an application that creates an alert upon receiving a message.
10. Write a mobile application that makes use of RSS feed.
11. Develop a mobile application to send an email.
TOTAL : 60 PERIODS
Ex No : 1
DEVELOP AN APPLICATION THAT USES GUI
COMPONENTS, FONT AND COLOURS
AIM :
To write an Android application program that uses GUI Components,
Fonts, and Colors.
PROCEDURE :
1. Open eclipse or android studio
2. Create a new android project
3. Select and double click your project name
4. Then, go to res folder and select layout double click the
activity_main.xml file
5. Enter your activity_main.xml code
6. Then, go to src folder and double click your MainActivity.java file
7. Enter your MainActivity.java code
8. Finally go to run configuration select your avd and run your android
program.
PROGRAM :
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="PTRCSE-CS8662”
android:textStyle="bold"
android:textSize="20sp"/>
CS8662 – MOBILE APPLICATION DEVELOPMENT 3
https://www.ptrcet.org Department of Computer Science and Engineering
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="31dp"
android:text="Change Colour"
android:textSize="20sp"/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button2"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:text="Change Font"
android:textSize="20sp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="Change Font Size"
android:textSize="20sp" />
</RelativeLayout>
MainActivity.java
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.graphics.Color;
import android.graphics.Typeface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t1=(TextView) findViewById(R.id.textView1);
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view1) {
t1.setTextSize(font);
font=font+4;
if(font==40)
font=20;
}
});
Button b2 = (Button) findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
switch(i)
{
case 1:
t1.setTextColor(Color.parseColor("#0000FF"));
break;
case 2:
t1.setTextColor(Color.parseColor("#00FF00"));
break;
case 3:
t1.setTextColor(Color.parseColor("#FF0000"));
break;
case 4:
t1.setTextColor(Color.parseColor("#800000"));
break;
}
i++;
if(i==5)
i=1;
}
});
Button b3 = (Button) findViewById(R.id.button3);
b3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
switch(j)
{
case 1:
t1.setTypeface(Typeface.SANS_SERIF);
break;
case 2:
t1.setTypeface(Typeface.SERIF);
CS8662 – MOBILE APPLICATION DEVELOPMENT 5
https://www.ptrcet.org Department of Computer Science and Engineering
break;
case 3:
t1.setTypeface(Typeface.MONOSPACE);
break;
case 4:
t1.setTypeface(Typeface.DEFAULT_BOLD);
break;
}
j++;
if(j==5)
j=1;
}
});
}
RESULT :
AIM :
To write an Android application program that uses Layout managers
and Event listeners.
PROCEDURE :
1. Open eclipse or android studio
2. Create a new android project
3. Select and double click your project name
4. Then, go to res folder and select layout double click the
activity_main.xml file
5. Enter your activity_main.xml code
6. Then, go to src folder and double click your MainActivity.java file
7. Enter your MainActivity.java code
8. Finally go to run configuration select your avd and run your android
program.
PROGRAM :
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LAYOUT and EVENT"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENTER NO 1 :" >
</TextView>
<EditText
android:id="@+id/edittext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.19"
android:inputType="number" >
</EditText>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENTER NO 2 :" >
</TextView>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:id="@+id/edittext2"
android:inputType="number">
</EditText>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
CS8662 – MOBILE APPLICATION DEVELOPMENT 11
https://www.ptrcet.org Department of Computer Science and Engineering
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout3" >
<Button
android:layout_width="wrap_content"
android:id="@+id/button1"
android:layout_height="wrap_content"
android:text="ADD"
android:layout_weight="0.50" />
<Button
android:layout_width="wrap_content"
android:id="@+id/button3"
android:layout_height="wrap_content"
android:text="SUB"
android:layout_weight="0.50" />
<Button
android:layout_width="wrap_content"
android:id="@+id/button2"
android:layout_height="wrap_content"
android:text="CLEAR"
android:layout_weight="0.50" />
</LinearLayout>
<View
android:layout_height="2px"
android:layout_width="fill_parent"
android:layout_below="@+id/linearLayout4"
android:background="#DDFFDD"/>
</RelativeLayout>
MainActivity.java
package com.example.second;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
CS8662 – MOBILE APPLICATION DEVELOPMENT 12
https://www.ptrcet.org Department of Computer Science and Engineering
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
{
txtData1.setText("");
txtData2.setText("");
}
catch(Exception e)
{
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
}
RESULT :
Thus, the Android application program was executed successfully and
verified.
OUTPUT :
If we click on CLEAR, then all the inputs are given in the EditText are cleared.
Ex No : 3
AN APPLICATION THAT DRAWS BASIC
GRAPHICAL PRIMITIVES ON THE SCREEN
AIM :
To write an Android application program that draws basic graphical
primitives on the screen.
PROCEDURE :
1. Open eclipse or android studio
2. Create a new android project
3. Select and double click your project name
4. Then, go to res folder and select layout double click the
activity_main.xml file
5. Enter your activity_main.xml code
6. Then, go to src folder and double click your MainActivity.java file
7. Enter your MainActivity.java code
8. Finally go to run configuration select your avd and run your android
program.
PROGRAM :
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="${relativePackage}.${activityClass}">
</RelativeLayout>
MainActivity.java
package com.example.three;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Context;
CS8662 – MOBILE APPLICATION DEVELOPMENT 17
https://www.ptrcet.org Department of Computer Science and Engineering
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
OUTPUT :
Ex No : 4
IMPLEMENT AN APPLICATION THAT USES
MULTI - THREADING
AIM :
To write an Android application program that implements Multi-
threading.
PROCEDURE :
1. Open eclipse or android studio
2. Create a new android project
3. Select and double click your project name
4. Then, go to res folder and select layout double click the
activity_main.xml file
5. Enter your activity_main.xml code
6. Then, go to src folder and double click your MainActivity.java file
7. Enter your MainActivity.java code
8. Finally go to run configuration select your avd and run your android
program.
PROGRAM :
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="PTRCSE - CS8662"
android:textStyle="bold"
android:textSize="10pt" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Start MULTITHREAD"
android:textStyle="bold"
android:onClick="fetchData" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_marginTop="16dp"
android:text="Main Thread" />
</RelativeLayout>
MainActivity.java
package com.example.four;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvOutput = (TextView) findViewById(R.id.textView2);
}
public void fetchData(View v) {
tvOutput.setText("Main PTRCSE - thread");
thread1.start();
CS8662 – MOBILE APPLICATION DEVELOPMENT 21
https://www.ptrcet.org Department of Computer Science and Engineering
thread2.start();
thread3.start();
}
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 5; i++)
{
try {
Thread.sleep(1005);
}
catch (InterruptedException e) {
e.printStackTrace();
}
handler.sendEmptyMessage(t1);
}
}
});
Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 5; i++)
{
try {
Thread.sleep(1002);
}
catch (InterruptedException e) {
e.printStackTrace();
}
handler.sendEmptyMessage(t2);
}
}
});
Thread thread3 = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 5; i++)
{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.sendEmptyMessage(t3);
}
}
});
Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
CS8662 – MOBILE APPLICATION DEVELOPMENT 22
https://www.ptrcet.org Department of Computer Science and Engineering
if(msg.what == t1) {
tvOutput.append("\nIn PTRCSE - thread 1");
}
if(msg.what == t2) {
tvOutput.append("\nIn PTRCSE - thread 2");
}
if(msg.what == t3) {
tvOutput.append("\nIn PTRCSE - thread 3");
}
}
};
}
RESULT :
Thus, the Android application program was executed successfully and
verified.
CS8662 – MOBILE APPLICATION DEVELOPMENT 23
https://www.ptrcet.org Department of Computer Science and Engineering
OUTPUT :
Ex No : 5
DEVELOP AN APPLICATION THAT MAKES
USE OF DATABASE
AIM :
To write an Android application program that makes use of database.
PROCEDURE :
1.
Open eclipse or android studio
2.
Create a new Android project
3.
Select and double click our project Name
4.
Then, go to res folder and select layout double click the
activity_main.xml file
5. Enter our activity_main.xml code
6. Then, go to res folder and select values double click the string.xml
file
7. Enter our string.xml code
8. Then, go to src folder and double click our MainActivity.java file
9. Enter our MainActivity.java code.
10. Finally go to run configuration select our AVD and run our Android
program.
PROGRAM :
activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="17dp"
android:text="@string/ptrcse_student_form"
android:textSize="10pt"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_x="19dp"
android:layout_y="60dp"
android:text="Registration No" />
<EditText
android:id="@+id/editRegistrationNo"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_x="122dp"
android:layout_y="55dp"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_x="17dp"
android:layout_y="112dp"
android:text="Student Name"
android:textAlignment="center" />
<EditText
android:id="@+id/editStudentName"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_x="119dp"
android:layout_y="109dp"
android:ems="10"
android:inputType="text" />
<TextView
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_x="19dp"
android:layout_y="164dp"
android:text="Year" />
<EditText
android:id="@+id/editYear"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_x="119dp"
android:layout_y="160dp"
android:ems="10"
CS8662 – MOBILE APPLICATION DEVELOPMENT 26
https://www.ptrcet.org Department of Computer Science and Engineering
android:inputType="text" />
<Button
android:id="@+id/butAdd"
android:layout_width="122dp"
android:layout_height="wrap_content"
android:layout_x="14dp"
android:layout_y="207dp"
android:text="ADD"
android:textStyle="bold" />
<Button
android:id="@+id/butDelete"
android:layout_width="122dp"
android:layout_height="wrap_content"
android:layout_x="150dp"
android:layout_y="207dp"
android:text="DELETE"
android:textStyle="bold" />
<Button
android:id="@+id/butModify"
android:layout_width="122dp"
android:layout_height="wrap_content"
android:layout_x="17dp"
android:layout_y="264dp"
android:text="MODIFY"
android:textStyle="bold" />
<Button
android:id="@+id/butView"
android:layout_width="122dp"
android:layout_height="wrap_content"
android:layout_x="150dp"
android:layout_y="264dp"
android:text="VIEW"
android:textStyle="bold" />
<Button
android:id="@+id/butViewAll"
android:layout_width="122dp"
android:layout_height="wrap_content"
android:layout_x="81dp"
android:layout_y="324dp"
android:text="VIEW ALL"
android:textStyle="bold" />
</AbsoluteLayout>
MainActivity.java
package com.example.five;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editRegistrationNo=(EditText)findViewById(R.id.editRegistrationNo);
editStudentName=(EditText)findViewById(R.id.editStudentName);
editYear=(EditText)findViewById(R.id.editYear);
butAdd=(Button)findViewById(R.id.butAdd);
butDelete=(Button)findViewById(R.id.butDelete);
butModify=(Button)findViewById(R.id.butModify);
butView=(Button)findViewById(R.id.butView);
butViewAll=(Button)findViewById(R.id.butViewAll);
butAdd.setOnClickListener(this);
butDelete.setOnClickListener(this);
butModify.setOnClickListener(this);
butView.setOnClickListener(this);
butViewAll.setOnClickListener(this);
db=openOrCreateDatabase("studentDB", Context.MODE_PRIVATE,
null);
db.execSQL("CREATE TABLE IF NOT EXISTS student(regno
VARCHAR,studname VARCHAR,year VARCHAR);");
}
public void onClick(View view)
{
CS8662 – MOBILE APPLICATION DEVELOPMENT 28
https://www.ptrcet.org Department of Computer Science and Engineering
if(view==butAdd)
{
if(editRegistrationNo.getText().toString().trim().length()==0 ||
editStudentName.getText().toString().trim().length()==0 ||
editYear.getText().toString().trim().length()==0)
{
showMessage("PTRCSE - Error", "Please enter All Details");
return;
}
db.execSQL("INSERT INTO student
VALUES('"+editRegistrationNo.getText()+"','"+editStudentName.getText()+
"','"+editYear.getText()+"');");
showMessage("Success", "Record added");
clearText();
}
if(view==butDelete)
{
if(editRegistrationNo.getText().toString().trim().length()==0)
{
showMessage("PTRCSE - Error", "Please enter Registration
No");
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
regno='"+editRegistrationNo.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("DELETE FROM student WHERE
regno='"+editRegistrationNo.getText()+"'");
showMessage("Success", "Record Deleted");
}
else
{
showMessage("PTRCSE - Error", "Invalid Registration No");
}
clearText();
}
if(view==butModify)
{
if(editRegistrationNo.getText().toString().trim().length()==0)
{
showMessage("PTRCSE - Error", "Please enter Registration
No");
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
regno='"+editRegistrationNo.getText()+"'", null);
CS8662 – MOBILE APPLICATION DEVELOPMENT 29
https://www.ptrcet.org Department of Computer Science and Engineering
if(c.moveToFirst())
{
db.execSQL("UPDATE student SET
studname='"+editStudentName.getText()+"',year='"+editYear.getText()+ "'
WHERE regno='"+editRegistrationNo.getText()+"'");
showMessage("Success", "Record Modified");
}
else
{
showMessage("PTRCSE - Error", "Invalid Rollno");
}
clearText();
}
if(view==butView)
{
if(editRegistrationNo.getText().toString().trim().length()==0)
{
showMessage("PTRCSE - Error", "Please enter Registration
No");
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
regno='"+editRegistrationNo.getText()+"'", null);
if(c.moveToFirst())
{
editStudentName.setText(c.getString(1));
editYear.setText(c.getString(2));
}
else
{
showMessage("PTRCSE - Error", "Invalid Registration No");
clearText();
}
}
if(view==butViewAll)
{
Cursor c=db.rawQuery("SELECT * FROM student", null);
if(c.getCount()==0)
{
showMessage("PTRCSE - Error", "No records found");
return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("Registration No: "+c.getString(0)+"\n");
buffer.append("Student Name: "+c.getString(1)+"\n");
CS8662 – MOBILE APPLICATION DEVELOPMENT 30
https://www.ptrcet.org Department of Computer Science and Engineering
buffer.append("Year: "+c.getString(2)+"\n\n");
}
showMessage("PTRCSE Student Details", buffer.toString());
}
}
string.xml
RESULT :
Thus, the Android application program was executed successfully and
verified.
CS8662 – MOBILE APPLICATION DEVELOPMENT 31
https://www.ptrcet.org Department of Computer Science and Engineering
OUTPUT :
After inserting all records… then we want to display all records, click on
‘VIEW ALL’
If we want to modify the existing record… give the inputs in the EditText, then
click on ‘MODIFY’
If we want to delete the existing record, First we give the Registration No, then
click on ‘DELETE’
If we want to insert a new record, but we didn’t give any values of any
column, it shows error message as,
Ex No : 6
DEVELOP A NATIVE APPLICATION THAT
USES GPS LOCATION INFORMATION
AIM :
To write an Android application program that uses GPS Location
information.
PROCEDURE :
1. Open eclipse or android studio
2. Create a new Android project
3. Select and double click our project Name
4. Then, go to res folder and select layout double click the
activity_main.xml file
5. Enter our activity_main.xml code
6. Then, go to src folder and double click our MainActivity.java file
7. Enter our MainActivity.java code
8. Enter our AndroidManifest.xml file
9. Finally go to run configuration select our AVD and run our Android
program.
PROGRAM:
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/butShowLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="154dp"
android:text="SHOW LOCATION"
android:textStyle="bold" />
</RelativeLayout>
CS8662 – MOBILE APPLICATION DEVELOPMENT 38
https://www.ptrcet.org Department of Computer Science and Engineering
MainActivity.java
package com.example.six;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
butShowLocation=(Button)findViewById(R.id.butShowLocation);
butShowLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
gps=new GPStrace(MainActivity.this);
if(gps.canGetLocation()){
double latitude=gps.getLatitude();
double longitude=gps.getLongtiude();
Toast.makeText(getApplicationContext(),"Your
Location is \nLat:"+latitude+"\nLong:"+longitude,
Toast.LENGTH_LONG).show();
}
else
{
gps.showSettingAlert();
}
}
});
}
}
GPStrace.java
package com.example.six;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
CS8662 – MOBILE APPLICATION DEVELOPMENT 39
https://www.ptrcet.org Department of Computer Science and Engineering
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
isGPSEnabled=locationManager.isProviderEnabled(LocationManager.G
PS_PROVIDER);
isNetworkEnabled=locationManager.isProviderEnabled(LocationManag
er.NETWORK_PROVIDER);
if(!isGPSEnabled && !isNetworkEnabled)
{
}
else{
this.canGetLocation=true;
if(isNetworkEnabled){
locationManager.requestLocationUpdates(LocationManager.NETWORK
_PROVIDER,MIN_TIME_BW_UPDATES,MIN_DISTANCE_CHANGE_FOR_UPD
ATES,this);
}
if(locationManager!=null){
location=locationManager.getLastKnownLocation(LocationManager.NE
TWORK_PROVIDER);
CS8662 – MOBILE APPLICATION DEVELOPMENT 40
https://www.ptrcet.org Department of Computer Science and Engineering
if(location !=null){
latitude=location.getLatitude();
longtitude=location.getLongitude();
}
}
}
if(isGPSEnabled){
if(location==null){
locationManager.requestLocationUpdates(LocationManager.GPS_PRO
VIDER,MIN_TIME_BW_UPDATES,MIN_DISTANCE_CHANGE_FOR_UPDATES
, this);
if(locationManager!=null){
location=locationManager.getLastKnownLocation(LocationManager.GP
S_PROVIDER);
if(location!=null){
latitude=location.getLatitude();
longtitude=location.getLongitude();
}
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return location;
}
longtitude=location.getLatitude();
}
return longtitude;
}
RESULT :
Thus, the Android application program was executed successfully and
verified.
CS8662 – MOBILE APPLICATION DEVELOPMENT 43
https://www.ptrcet.org Department of Computer Science and Engineering
OUTPUT :
Ex No : 7
IMPLEMENT AN APPLICATION THAT
WRITES DATA TO THE SD CARD
AIM :
To write an Android application program that writes the data to the SD
card.
PROCEDURE :
1. Open eclipse or android studio
2. Create a new Android project
3. Select and double click our project Name
4. Then, go to res folder and select layout double click the
activity_main.xml file
5. Enter our activity_main.xml code
6. Then, go to src folder and double click our MainActivity.java file
7. Enter our MainActivity.java code
8. Enter our AndroidManifest.xml file
9. Finally go to run configuration select our AVD and run our Android
program.
PROGRAM:
activity_main.xml
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SAVE DATA"
android:textStyle="bold" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SHOW DATA"
android:textStyle="bold" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
ActivityMain.java
package com.example.seven;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import android.os.Environment;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
Save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Message1=message.getText().toString();
try{
Toast.makeText(getBaseContext(),"PTRCSE - Data
Saved",Toast.LENGTH_LONG).show();
}catch(IOException e){
e.printStackTrace();
}
}catch (FileNotFoundException e){
e.printStackTrace();
}
}
});
Load.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
try{
File sdcard=Environment.getExternalStorageDirectory();
File directory=new
File(sdcard.getAbsolutePath()+"/MyDirectory");
File file=new File(directory,"textfile.txt");
FileInputStream fis=new FileInputStream(file);
InputStreamReader isr=new InputStreamReader(fis);
char[] data=new char[100];
String final_data="";
int size;
try{
CS8662 – MOBILE APPLICATION DEVELOPMENT 47
https://www.ptrcet.org Department of Computer Science and Engineering
while((size=isr.read(data))>0)
{
//read a data from file
String read_data=String.copyValueOf(data,0,size);
final_data+=read_data;
data=new char[100];
}
//display the data in output
Toast.makeText(getBaseContext(),"PTRCSE - Message :
"+final_data,Toast.LENGTH_LONG).show();
}catch(IOException e){
e.printStackTrace();
}
}catch (FileNotFoundException e){
e.printStackTrace();
}
}
});
}
}
AndroidManifest.xml
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.seven.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
CS8662 – MOBILE APPLICATION DEVELOPMENT 48
https://www.ptrcet.org Department of Computer Science and Engineering
</intent-filter>
</activity>
</application>
</manifest>
RESULT :
Thus, the Android application program was executed successfully and
verified.
OUTPUT :
AIM :
To write an Android application program that creates an alert upon
receiving a message.
PROCEDURE :
1. Open eclipse or android studio
2. Create a new android project
3. Select and double click your project name
4. Then, go to res folder and select layout double click the
activity_main.xml file
5. Enter your activity_main.xml code
6. Then, go to src folder and double click your MainActivity.java file
7. Enter your MainActivity.java code
8. Finally go to run configuration select your avd and run your android
program.
PROGRAM :
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/text"
android:layout_marginTop="32dp"
android:text="SHOW ALERT BOX"
android:textSize="20sp" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="21dp"
android:text="PTRCSE - CS8662"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
MainActivity.java
package com.example.eight;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
Toast.LENGTH_LONG).show();
}
});
RESULT :
Thus, the Android application program was executed successfully and
verified.
CS8662 – MOBILE APPLICATION DEVELOPMENT 54
https://www.ptrcet.org Department of Computer Science and Engineering
OUTPUT :
Ex No : 9
DEVELOP A MOBILE APPLICATION
TO SEND AN e-MAIL
AIM :
To write an Android application program to send an e-Mail.
PROCEDURE :
1. Open eclipse or android studio
2. Create a new android project
3. Select and double click your project name
4. Then, go to res folder and select layout double click the
activity_main.xml file
5. Enter your activity_main.xml code
6. Then, go to src folder and double click your MainActivity.java file
7. Enter your MainActivity.java code
8. Finally go to run configuration select your avd and run your android
program.
PROGRAM :
activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:hint="E-mail">
<requestFocus />
</EditText>
<EditText
android:id="@+id/et_subject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:hint="Subject"
android:layout_marginTop="10dp" />
<EditText
android:id="@+id/et_message"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="10dp"
android:inputType="textMultiLine"
android:ems="10"
android:hint="Message"
android:gravity="left" />
<Button
android:id="@+id/b_send"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="SEND"
android:textSize="20sp" />
</LinearLayout>
MainActivity.java
package com.example.nine;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CS8662 – MOBILE APPLICATION DEVELOPMENT 58
https://www.ptrcet.org Department of Computer Science and Engineering
et_email=(EditText)findViewById(R.id.et_email);
et_subject=(EditText)findViewById(R.id.et_subject);
et_message=(EditText)findViewById(R.id.et_message);
b_send=(Button)findViewById(R.id.b_send);
b_send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String to=et_email.getText().toString();
String subject=et_subject.getText().toString();
String message=et_message.getText().toString();
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "PTRCSE -
Select Email App"));
}
});
}
}
RESULT :
Thus, the Android application program was executed successfully and
verified.
OUTPUT :
Ex No : 10
DEVELOP AN APPLICATION THAT MAKES
USE OF NOTIFICATION MANAGER
AIM :
To write an Android application program that makes use of Notification
Manager.
PROCEDURE :
1. Open eclipse or android studio
2. Create a new android project
3. Select and double click your project name
4. Then, go to res folder and select layout double click the
activity_main.xml file
5. Enter your activity_main.xml code
6. Then, go to src folder and double click your MainActivity.java file
7. Enter your MainActivity.java code
8. Finally go to run configuration select your avd and run your android
program.
PROGRAM :
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text="PTRCSE - CS8662"
android:textStyle="bold"
android:textSize="30sp" />
<Button
android:id="@+id/bt_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp"
android:text="NOTIFICATION"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
activity_notification.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NotificationActivity" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/notifymessagetextview"
android:textSize="25sp"
android:gravity="center" />
</RelativeLayout>
MainActivity.java
package com.example.ten;
import android.os.Bundle;
import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.view.View;
import android.widget.*;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btNotification=(Button)findViewById(R.id.bt_notification);
btNotification.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String message="This is a PTRCSE - CS8662
Notification Demo";
NotificationCompat.Builder builder=new
NotificationCompat.Builder
(MainActivity.this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("PTRCSE - New Notification")
.setContentText(message)
.setAutoCancel(true);
Intent intent=new
Intent(MainActivity.this,NotificationActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("message", message);
PendingIntent
pendingIntent=PendingIntent.getActivity(MainActivity.this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
NotificationManager
notificationmanager=(NotificationManager)getSystemService(Context.NOTIFI
CATION_SERVICE);
notificationmanager.notify(0,builder.build());
}
});
}
}
NotificationActivity.java
package com.example.ten;
import android.os.Bundle;
import android.widget.TextView;
import android.app.Activity;
TextView textview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification);
textview=(TextView)findViewById(R.id.notifymessagetextview);
String message=getIntent().getStringExtra("message");
textview.setText(message);
}
}
RESULT :
Thus, the Android application program was executed successfully and
verified.
CS8662 – MOBILE APPLICATION DEVELOPMENT 65
https://www.ptrcet.org Department of Computer Science and Engineering
OUTPUT :