You are on page 1of 97

PRINCE SHRI VENKATESHWARA PADMAVATHY

ENGINEERING COLLEGE
PONMAR,CHENNAI-600127

DEPARTMENT OF COMPUTER SCIENCE AND


ENGINEERING
(B.E. - SIXTH SEMESTER)

CS8662 – MOBILE APPLICATION DEVELOPMENT


LABORATORY
2021-2022

NAME : THARUN KUMAR L

REGISTER NO : 411719104053

COURSE : BACHELOR OF ENGINEERING

BATCH : COMPUTER SCIENCE ENGINEERING


PRINCE SHRI VENKATESHWARA PADMAVATHY
ENGINEERING COLLEGE
PONMAR, CHENNAI – 600127

Name : THARUN KUMAR L

Register No : 411719104053

Semester : 06

Branch : COMPUTER SCIENCE ENGINEERING

Certified that this is a Bonafide Record of practical work done by the above

student in “CS8662-MOBILE APPLICATION DEVELOPMENT” during the

year 2021-2022.

Submitted for Practical Examination held on …………………..

Signature of the Faculty In-Charge Signature of the Principal

INTERNAL EXAMINER EXTERNAL EXAMINER


INDEX
S.NO DATE EXPERIMENT PAGE NO SIGNATURE

1 Develop an application that uses GUI components, 1

Font and Colors

2 Develop an application that uses Layout Managers 7

and Event Listeners

3 Write an application that draws Basic Graphical 12

Primitives on the screen

4 Develop an application that makes use of database 16

5 Develop an application that makes use of 24

Notification Manager

6 Implement an application that uses multi-threading 31

7 Develop a native application that uses GPS location 36

information

8 Implement an application that writes data to the SD 45

Card

9 Implement an application that creates an alert upon 53

receiving a message

10 Write a mobile application that makes use of RSS 65

Feed

11 Develop a mobile application to send an email 78

12 Develop a Mobile application for simple needs 82

(Mini Project)
411719104053

Ex. No. 1 FONTS & COLORS

Aim
To develop an application that uses GUI components, Font and Colors.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
Step 5: Use F2 key to edit the name of the tools
Step 6: Use Ctrl + tab in the activitymain.xml file to view the hints without typing fully

Step 7: Open MainActivity.java file and type the code inside the class
Step 8: Steps to create a emulator
8 (a): Got to menu Window → Android Virtual Device Manager
8(b): Select New → Type AVD name and click OK
Step 9: Stop the program

Steps to Create an Emulator


• Window → Android Virtual Device Manager →AVD name

Steps to open android project

• File → new →Android Application Project

1
411719104053

2
411719104053

PROGRAM CODING
//GUI COMPONENTS-FONTS AND COLORS

MainActivity.java
package com.example.admin.actionandevent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
float font=24;int i=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t1=(TextView)findViewById(R.id.textView);
Button b1=(Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
t1.setTextSize(font);
font = font + 4;

3
411719104053

if (font == 40) {
font = 20;
} }
});

Button b2=(Button)findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v)
{
Switch(i)
{
case 1:t1.setTextColor(Color.parseColor("#00ff00"));
i++;
break;
case 2:t1.setTextColor(Color.parseColor("#ff0000"));
i++;
break;
case 3:t1.setTextColor(Color.parseColor("#0000ff"));
i++;
break;
case 4:t1.setTextColor(Color.parseColor("#00f0f0"));
i++;
break;
default:break;
}
if(i==5)
i=1;
}
});
}
}

Activity_main.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="wrap_content"
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="com.example.admin.actionandevent.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
4
411719104053

android:text="welcome to mobile application lab"


android:id="@+id/textView" />

5
411719104053

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="change font size"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="112dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="change text color"
android:id="@+id/button2"
android:layout_marginTop="240dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/button"
android:layout_alignStart="@+id/button" />
</RelativeLayout>

6
411719104053

OUTPUT

CHANGED COLOR AND FONT SIZE

RESULT

Thus the mobile application that uses GUI components, Font and Colors has been developed
successfully.

7
411719104053

Ex. No. 2 LAYOUT MANAGERS & EVENT LISTENERS

Aim
To develop an application that uses Layout Managers and event listeners
Algorithm

Step 1: Start the program


Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
4(a): insert an image
4(a).1:Copy the image from the system
4(a).2:Project Explorer window res Drawable rightclick paste

4(a).3:selectimageview in layout window place it in the design.In the properties of image


view set the src field as the path to that image selected.
4(b): insert plaintext for username and a password field for the password
Step 5: Use F2 key to edit the name of the tools
Step 6: Open MainActivity.java file and type the code inside the class
6(a):Get the username and password from the user
6(b):check if the username and password are valid then display an authenticated user

And change the background color.


6(c):Else display to Check the credentials
Step 7: Steps to create a emulator
7 (a): Got to menu Window → Android Virtual Device Manager
7(b): Select New → Type AVD name and click OK
Step 8: Stop the program

8
411719104053

PROGRAM CODING
//LAYOUT MANAGERS AND EVENT LISTENERS

MainActivity.java
package com.example.admin.guifont10;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button btn;
RelativeLayout canvas;
EditText edtuser,edtpass;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=(Button)findViewById(R.id.button);
edtuser=(EditText)findViewById(R.id.edtusername);
edtpass=(EditText)findViewById(R.id.edtpassword);
canvas=(RelativeLayout)findViewById(R.id.canvas);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username=null,password=null;
username=edtuser.getText().toString();
password=edtpass.getText().toString();
if(username.equals("prince")&&password.equals("1234"))
{
Toast.makeText(getApplicationContext(),"user
authenticated",Toast.LENGTH_LONG).show();
canvas.setBackgroundResource(R.color.colorAccent);
}
else
Toast.makeText(getApplicationContext(),"check your
credentials",Toast.LENGTH_LONG).show();

}
});
}
}

9
411719104053

Activity_main.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"
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="com.example.admin.guifont10.MainActivity"
android:id="@+id/canvas">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/flower"
android:contentDescription=""
android:layout_gravity="center"
android:layout_marginBottom="389dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username"
android:id="@+id/edtuser"
android:layout_alignParentTop="true"
android:layout_marginTop="126dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:id="@+id/edtpwd"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edtusername"
android:layout_alignTop="@+id/edtuser"
android:layout_alignRight="@+id/imageView"
android:layout_alignEnd="@+id/imageView"
android:layout_marginRight="96dp"
10
411719104053

android:layout_marginEnd="96dp"
android:layout_toRightOf="@+id/edtuser"
android:layout_toEndOf="@+id/edtuser" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/edtpassword"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username is &quot;prince&quot; and password is&quot;1234&quot;"
android:id="@+id/textView"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="81dp" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="change bg color"
android:id="@+id/button"
android:layout_above="@+id/textView"
android:layout_centerHorizontal="true" />
</RelativeLayout>

11
411719104053

OUTPUT

RESULT

Thus a Simple Android Application that uses Layout Managers and Event Listeners is
developed and executed successfully.

12
411719104053

Ex. No. 3 BASIC GRAPHICAL PRIMITIVES

Aim
To develop an application that draws basic graphical primitives on the screen.
Algorithm

Step 1: Start the program


Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design an empty layout in the palette window
Step 5: Use F2 key to edit the name of the tools
Step 6: Open MainActivity.java file and type the code inside the class
6(a): Create a myView() method and set the content view to myView
6(b):inmyView() method define the OnDraw() method to draw all the basic graphical
primitives.
6(c):drawCircle() method is used to draw the circle on the screen at the specified pixel
position and filled with specified paint color.
6(d):drawRect() method is used to draw the Rectangle on the Screen at the specified pixel
position and filled with specified paint color.

6(e):drawLine() method is used to draw the Line onn the Screen at the specified pixel
position and filled with specified paint color
Step 7: Steps to create a emulator
7 (a): Got to menu Window → Android Virtual Device Manager
7(b): Select New → Type AVD name and click OK
Step 8: Stop the program

13
411719104053

PROGRAM CODING
//BASIC GRAPHICAL PRIMITIVES
MainActivity.java
package com.example.admin.basicgraphicalprimitivesapp;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new myView(this));
}
private class myView extends View
{
public myView(Context context)
{
super(context);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Paint paint=new Paint();
paint.setTextSize(40);
paint.setColor(Color.GREEN);
canvas.drawText("Circle", 55, 30, paint);
paint.setColor(Color.RED);
canvas.drawCircle(100, 150, 100, paint);
paint.setColor(Color.GREEN);
canvas.drawText("Rectangle", 255, 30, paint);
paint.setColor(Color.YELLOW);
canvas.drawRect(250, 50, 400, 350, paint);
paint.setColor(Color.GREEN);
canvas.drawText("Square", 55, 430, paint);
paint.setColor(Color.BLUE);
canvas.drawRect(50, 450, 150, 550, paint);
paint.setColor(Color.GREEN);
canvas.drawText("Line", 255, 430, paint);
paint.setColor(Color.GREEN);
canvas.drawLine(250, 550,350 , 550, paint);
}
}
14
411719104053

Activity_main.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"
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="com.example.admin.basicgraphicalprimitivesapp.MainActivity"
android:id="@+id/canvas">
</RelativeLayout>

15
411719104053

OUTPUT

RESULT
Thus, the mobile application that draws basic graphical primitives on the screen has been developed
successfully

16
411719104053

Ex. No. 4 CREATE DATABASE USING ANDROID APPLICATION

Aim
To develop an application that makes use of database.

Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
4(a): insert five buttons for various operations on the database such as
Add,Modify,Delete,View and view_all
4(b):insert three plaintext field one for Employee id,Employee name and Employee Salary.

Step 5: Use F2 key to edit the name of the tools


Step 6: Open MainActivity.java file and type the code inside the class
6(a): create the database using openorCreate() method and execute the SQL commands
using execSOL() method.

6(b):setonClickListener() method for each button.


6(c):define the code for Add button to get the employee id,employee name and employee
Salary from the user and add it to the database using SQL INSERT command.
6(d):define the codefor Delete button to get the Employee id and delete that particular
record from database using SQL DELETE command.

6(e):define the code for Modify button to get the Employee id,employee name and employee
salary and modify the record in the database using SQL UPDATE command.
6(f):define the code for view_all button to execute SOL SELECT command to display all the
records from the database.
6(g): define the code for view button to get the employee id and display the particular record
from the database using SQL SELECT command .

Step 7: Steps to create a emulator


7 (a): Got to menu Window → Android Virtual Device Manager
7(b): Select New → Type AVD name and click OK
Step 8: Stop the program

17
411719104053

PROGRAM CODING
//CREATE DATABASE USING ANDROID APPLICATION

MainActivity.java
package com.example.admin.empdetails;
import android.app.AlertDialog;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


EditText editEmpid,editName,editsalary;
Button btnAdd,btnDelete,btnModify,btnView,btnViewAll;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editEmpid=(EditText)findViewById(R.id.editEmpid);
editName=(EditText)findViewById(R.id.editName);
editsalary=(EditText)findViewById(R.id.editsalary);
btnAdd=(Button)findViewById(R.id.btnAdd);
btnDelete=(Button)findViewById(R.id.btnDelete);
btnModify=(Button)findViewById(R.id.btnModify);
btnView=(Button)findViewById(R.id.btnView);
btnViewAll=(Button)findViewById(R.id.btnViewAll);
btnAdd.setOnClickListener(this);
btnDelete.setOnClickListener(this);
btnModify.setOnClickListener(this);
btnView.setOnClickListener(this);
btnViewAll.setOnClickListener(this);
db=openOrCreateDatabase("EmployeeDB", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS employee(empid VARCHAR,name
VARCHAR,salary VARCHAR);");
}
public void onClick(View view)
{
if(view==btnAdd)
{
if(editEmpid.getText().toString().trim().length()==0||
editName.getText().toString().trim().length()==0||
editsalary.getText().toString().trim().length()==0)
{
18
411719104053

showMessage("Error", "Please enter all values");


return;
}
db.execSQL("INSERT INTO employee
VALUES('"+editEmpid.getText()+"','"+editName.getText()+
"','"+editsalary.getText()+"');");
showMessage("Success", "Record added");
clearText();
}
if(view==btnDelete)
{
if(editEmpid.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Employee id");
return;
}
Cursor c=db.rawQuery("SELECT * FROM employee WHERE
empid='"+editEmpid.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("DELETE FROM employee WHERE
empid='"+editEmpid.getText()+"'");
showMessage("Success", "Record Deleted");
}
else
{
showMessage("Error", "Invalid Employee id");
}
clearText();
}
if(view==btnModify)
{
if(editEmpid.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Employee id");
return;
}
Cursor c=db.rawQuery("SELECT * FROM employee WHERE
empid='"+editEmpid.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("UPDATE employee SET
name='"+editName.getText()+"',salary='"+editsalary.getText()+
"' WHERE empid='"+editEmpid.getText()+"'");
showMessage("Success", "Record Modified");
}
else
{
showMessage("Error", "Invalid Rollno");
19
411719104053

}
clearText();
}
if(view==btnView)
{
if(editEmpid.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Employee id");
return;
}
Cursor c=db.rawQuery("SELECT * FROM employee WHERE
empid='"+editEmpid.getText()+"'", null);
if(c.moveToFirst())
{
editName.setText(c.getString(1));
editsalary.setText(c.getString(2));
}
else
{
showMessage("Error", "Invalid Employee id");
clearText();
}
}
if(view==btnViewAll)
{
Cursor c=db.rawQuery("SELECT * FROM employee", null);
if(c.getCount()==0)
{
showMessage("Error", "No records found");
return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("Employee id: "+c.getString(0)+"\n");
buffer.append("Name: "+c.getString(1)+"\n");
buffer.append("salary: "+c.getString(2)+"\n\n");
}
showMessage("Employee Details", buffer.toString());
}

}
public void showMessage(String title,String message)
{
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
20
411719104053

}
public void clearText()
{
editEmpid.setText("");
editName.setText("");
editsalary.setText("");
editEmpid.requestFocus();

}
}
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:stretchColumns="0"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="EMPLOYEE DATABASE MANAGEMENT APPLICATION"
android:layout_x="18dp"
android:layout_y="9dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:text="empid"
android:layout_x="30dp"
android:layout_y="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText android:id="@+id/editEmpid"
android:inputType="number"
android:layout_x="150dp"
android:layout_y="50dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
<TextView android:text="name"
android:layout_x="30dp"
android:layout_y="100dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText android:id="@+id/editName"
android:inputType="text"
android:layout_x="150dp"
android:layout_y="100dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
<TextView android:text="salary"
android:layout_x="30dp"
android:layout_y="150dp"
android:layout_width="wrap_content"

21
411719104053

android:layout_height="wrap_content"/>
<EditText android:id="@+id/editsalary"
android:inputType="number"
android:layout_x="150dp"
android:layout_y="150dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnAdd"
android:text="add"
android:layout_x="30dp"
android:layout_y="200dp"
android:layout_width="130dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnDelete"
android:text="delete"
android:layout_x="160dp"
android:layout_y="200dp"
android:layout_width="130dp"
android:layout_height="40dp"/>n
<Button android:id="@+id/btnModify"
android:text="modify"
android:layout_x="30dp"
android:layout_y="250dp"
android:layout_width="130dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnView"
android:text="view"
android:layout_x="160dp"
android:layout_y="250dp"
android:layout_width="130dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnViewAll"
android:text="view_all"
android:layout_x="85dp"
android:layout_y="300dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
</AbsoluteLayout>

22
411719104053

OUTPUT
1. Add a record into the database

2. Delete a record from a database

23
411719104053

3. Modify a record in the database

4. View all

RESULT
Thus the android application that uses the database has been developed successfully

24
411719104053

Ex. No. 5 Alarm application

Aim
To develop an mobile application that creates an alarm clock.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
4(a):A button that is used to set the target time.
4(b):A text box to display the Alarm time that is set
Step 5: Open MainActivity.java file and type the code inside the class to do the following
5(a):Create a time picker dialog object using the TimePickerDialog class when the button to set
the alarm is clicked the onclick() method is invoked to display the time in hours and minutes using
the opentimepickerDialog()method.
5(b):In the openTimePickerDialog() method use the calendar class and the timepickerDialog
class objects to create a time picker window with the title Set AlarmTime
5(c):OnTimeSet() method is used to set the alarm time and compare the Alarm set time with
the current time.if it becomes true then setAlarm() method is invoked.
5(d):setAlarm() method is used to display the Alarm set time on the mobile screen in the text
area.
5(e):Using the objects of Intentclass and the alarm manager class it gets the system services and
an intent to the AlarmReceiver class.
Step 6: create a AlarmReceiver .java file in the src directory and in that class define the onReceiver()
method to display the toast message that the alarm has been received.
Step 7:in the AndroidManifest.xml file use the receiver xml tag with android:name attribute and
android:process attribute to connect with the remote AlarmReceiver class.
Step 8: Launch the application using the emulator.
Step 9: Stop the program.

25
411719104053

CODING
//ALARM
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="admin.example.com.alarm">

<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"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".AlarmReceiver" android:process=":remote"/>
</application>
</manifest>

Main_Activity.java
package admin.example.com.alarm;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
26
411719104053

import java.util.Calendar;

public class MainActivity extends AppCompatActivity {


TimePicker myTimePicker;
Button buttonstartSetDialog;
TextView textAlarmPrompt;
TimePickerDialog timePickerDialog;

final static int RQS_1 = 1;

/** Called when the activity is first created. */


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textAlarmPrompt = (TextView)findViewById(R.id.alarmprompt);
buttonstartSetDialog = (Button)findViewById(R.id.startSetDialog);
buttonstartSetDialog.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
textAlarmPrompt.setText("");
openTimePickerDialog(false);
}});}
private void openTimePickerDialog(boolean is24r){
Calendar calendar = Calendar.getInstance();
timePickerDialog = new TimePickerDialog(
MainActivity.this,
onTimeSetListener,
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
is24r);
timePickerDialog.setTitle("Set Alarm Time");
timePickerDialog.show(); }
TimePickerDialog.OnTimeSetListener onTimeSetListener = new
TimePickerDialog.OnTimeSetListener(){
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

Calendar calNow = Calendar.getInstance();


Calendar calSet = (Calendar) calNow.clone();

calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
calSet.set(Calendar.MINUTE, minute);

27
411719104053

calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);
if(calSet.compareTo(calNow) <= 0){
//Today Set time passed, count to tomorrow
calSet.add(Calendar.DATE, 1);
}
setAlarm(calSet);
}};
private void setAlarm(Calendar targetCal){
textAlarmPrompt.setText(
"\n\n***\n"
+ "Alarm is set@ " + targetCal.getTime() + "\n"
+ "***\n");
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1,
intent, 0);
AlarmManager alarmManager =
(AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(),
pendingIntent);
}
}
AlarmReceiver.java
package admin.example.com.alarm;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver {


@Override
public void onReceive(Context arg0, Intent arg1) {
Toast.makeText(arg0, "Alarm received!", Toast.LENGTH_LONG).show();

}
}

28
411719104053

Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/Title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical|center_horizontal"
android:text="ALARM CLOCK"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/startSetDialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set Target Time"/>
<TextView
android:id="@+id/alarmprompt"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout/>

29
411719104053

OUTPUT:

30
411719104053

RESULT
Thus, the mobile application that creates an alarm clock has been developed successfully.

31
411719104053

EX NO :6 MULTITHREADING

Aim
To develop an application to implement multithreading concept.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project.
Step 3: Output wizard in layout → activitymain.xml → graphical layout.
Step 4: Design the required tool in the palette window.
Step 5: Use F2 key to edit the name of the tools

Step 6: Open MainActivity.java file and type the code inside the class.
Step 7: Create a button named Start Multithreading and set onclick event as fetchData()
method in Activity_main.xml.
Step 8: Define fetchData() method to perform multithreading.
Step 9: Use Thread class for creating the thread.
9(a): set start() method to initialize the thread.
9(b): set run() method for each thread to execute the thread.
9(c): set sleep() method to make the thread to enter into the waiting state.
Step 10: create Handler class for handling thread messages.
Step 11: Steps to create a emulator
11 (a): Go to menu Window → Android Virtual Device Manager
11(b): Select New → Type AVD name and click OK
Step 12: Stop the program

32
411719104053

PROGRAM CODING:
//MULTITHREADING
Main_Activity.java
package admin.example.com.multithread;

import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


private TextView tvoutput;
private static final int t1=1;
private static final int t2=2;
private static final int t3=3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvoutput=(TextView)findViewById(R.id.textView1);
}
public void fetchData(View v)
{
tvoutput.setText("mainThread");
thread1.start();
thread2.start();
thread3.start();
}
Thread thread1=new Thread(new Runnable() {
@Override
public void run() {
for(int i=0;i<5;i++)
{
try{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
33
411719104053

handler.sendEmptyMessage(t1);
}
}
});
Thread thread2=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(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(t1);
}
}
});
Handler handler=new Handler()
{
public void handleMessage(android.os.Message msg)
{
if(msg.what==t1)
{
tvoutput.append("\n in thread 1");
}
if(msg.what==t2)
{
tvoutput.append("\n in thread 2");
}
if(msg.what==t3)
{
34
411719104053

tvoutput.append("\n in thread 3");


}
}
};
}

Activity_main.xml:
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/info" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="fetchData"
android:text="Start MULTITHREAD" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Main thread" />
</LinearLayout>

35
411719104053

OUTPUT:

RESULT
Thus the android application to implement Multithreading concept has been developed
successfully.
36
411719104053

Ex. No. 7 GPS APPLICATION

Aim
To develop an native application that uses GPS location information
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
4(a):A button that is used to show the location
Step 5: Open MainActivity.java file and type the code inside the class to do the following
5(a):when the show location button is clicked create an object for the GPStrace class
and using that object check whether we can get the location using cangetLocation() method.
5(b): if true,show the latitude and the longitude using toast message
Step 6: create a GPStrace.java file in the srcdirectory and write the code
6(a):getlocation() method is used to get the location using the LocationManeger object.
6(b):isGPSEnabled field is used to check whether the GPS service is enabled or not.
6(c):isNetworkEnabled field is used to check whether the network is enabled or not.
6(d):if the isNetworkEnabled is true then return the location by checking the manifest
fie permission.
6(e):in the showSettingalert() method specify whether all the services and permissions
required to retrieve the GPS location are enabeled or not
Step 7:in the AndroidManifest.xml file use the uses-permission xml tag to give the internet
permission.
Step 8: Launch the application using the emulator then go to tools->android->android device
manager->emulator control. Send the loction information to the emulator.
Step 9: Stop the program.

37
411719104053

PROGRAM CODING:
//GPS
AndroidMenifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.gpspri" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Main_Activity.java
package com.example.admin.gps;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


Button btnShowLocation;
GPStrace gps;
38
411719104053

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btnShowLocation=(Button)findViewById(R.id.show_Location);
btnShowLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
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.admin.gpspri;
import android.Manifest;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;

public class GPStrace extends Service implements LocationListener


{
private final Context context;

39
411719104053

boolean isGPSEnabled = false;


boolean canGetLocation = false;
boolean isNetworkEnabled = false;
Location location;
double latitude;
double longitude;
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10;
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1;
public LocationManager locationManager;
public GPStrace(Context context) {
this.context = context;
getLocation();
}
public Location getLocation() {
try {
locationManager = (LocationManager)
context.getSystemService(LOCATION_SERVICE);
isGPSEnabled =
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled =
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#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 ActivityCompat#requestPermissions for more details.
return location;
}

locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
40
411719104053

}
if (locationManager != null) {
location =
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
if (isGPSEnabled) {
if (location == null) {

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location =
locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}

public void stopUsingGPS() {


if (locationManager != null) {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#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

41
411719104053

// for ActivityCompat#requestPermissions for more details.


return;
}
locationManager.removeUpdates(GPStrace.this);
}
}
public double getLatitude(){
if(location!=null){
latitude=location.getLatitude();
}
return latitude;
}
public double getLongtiude(){
if(location!=null){
longitude=location.getLongitude();
}
return longitude;
}
public boolean canGetLocation(){
return this.canGetLocation;
}
public void showSettingAlert(){
AlertDialog.Builder alertDialog=new AlertDialog.Builder(context);
alertDialog.setTitle("GPS is settings");
alertDialog.setMessage("GPS is not enabled.Do you want to go to setting menu?");
alertDialog.setPositiveButton("settings", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which){
Intent intent=new
Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
context.startActivity(intent);
}
});
alertDialog.setNegativeButton("cancel", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
alertDialog.show();
}
@Override
public void onLocationChanged(Location location) {

42
411719104053

// TODO Auto-generated method stub


}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}

Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/show_Location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show_Location"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>

43
411719104053

OUTPUT:

44
411719104053

RESULT
Thus, the mobile application that uses GPS location information has been developed
successfully.

45
411719104053

EX NO:8 SD-CARD

Aim
To Implement an application that writes data to the SD card.

Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
4(a): Two buttons are placed one is used for saving the data into the sdcard and other
is to load the data from sdcard
4(b): A textfield is used to write the data which is t be saved in the sdcard
Step 5: Open MainActivity.java file and type the code inside the class to do the following
5(a): get the message from the edittext component once the save button is clicked.
5(b): invoke the getExternalStorageDirectory() method using the Environment class
5(c): Create a fileDirectory in the sdcard called “mydirectory” using the mkdirs()
method.
5(d): Write the message into a text file using the file outpustreams and save it in the
directory.
5(e): when the load button is clicked get the message from the file which is placed in
mydirectory of the external sdcard and display it to the user using the toast message
Step 6 : In the AndroidManifest.xml file use the uses-permission xml tag to give the Write
_external storage permission
Step 7: Launch the application using the emulator.
Step 8: Stop the program

46
411719104053

PROGRAM CODING:
//SDCARD STORAGE
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.sdcard_harsh"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application
android:icon="@mipmap/ic_launcher"
android:label="SDCARD" >
<activity
android:name=".MainActivity"
android:label="SDCARD" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</menifest>
Main_Activity.java
package com.example.admin.sdcard;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;
package com.example.admin.sdcard;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;

47
411719104053

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

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;

public class MainActivity extends AppCompatActivity {

/** Called when the activity is first created. */


Button save,load;
EditText message;
TextView t1;
String Message1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
save=(Button) findViewById(R.id.button1);
load=(Button) findViewById(R.id.button2);
message=(EditText) findViewById(R.id.editText1);
t1=(TextView) findViewById(R.id.textView1);
save.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
//Get message from user store in message1 variable
Message1 =message.getText().toString();
try{
//Create a new folder called MyDirectory in SDCard
File sdcard= Environment.getExternalStorageDirectory();
File directory=new File(sdcard.getAbsolutePath()+"/MyDirectory");
directory.mkdirs();
//Create a new file name textfile.txt inside MyDirectory
File file=new File(directory,"textfile.txt");
//Create File Outputstream to read the file
FileOutputStream fou=new FileOutputStream(file);
OutputStreamWriter osw=new OutputStreamWriter(fou);
try{

48
411719104053

//write a user data to file


osw.append(Message1);
osw.flush();
osw.close();
Toast.makeText(getBaseContext(), "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{
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(),"Message:"+final_data,Toast.LENGTH_LONG).show();
}catch(IOException e){
e.printStackTrace();
}
}catch (FileNotFoundException e){
e.printStackTrace();
}
}

49
411719104053

});
}
Activity_main.xml:

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0000ff"
android:orientation="vertical" >

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<requestFocus />
</EditText>

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SAVE DATA" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SHOW DATA" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>

50
411719104053

OUTPUT:

51
411719104053

52
411719104053

RESULT
Thus the android application for writing data into the SD-card Storage has been developed
successfully.

53
411719104053

Ex. No. 9 ALERT APPLICATION

Aim
To develop an application that creates alert upon receiving a message.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
Step 5: Use F2 key to edit the name of the tools
Step 6: Use Ctrl + tab in the activitymain.xml file to view the hints without typing fully
Step 7: Open MainActivity.java file and type the code inside the class
Step 8 :CreateRadioGroup for each question and set OnCheckedChangeListener() for
each RadioGroup.
Step9: define code for OnCheckedChanged() to get the answer.
9(a): define switch case to assign the score to the selected answer for each
RadioGroup.
Step 10: create a button named Submit and set OnClickListener() to that button.
Step 11: Create AlertDialogBuilder class for showing alerts.
11(a): set alert title as SHOW RESULT and alert message.
11(b): define code for setPositiveButton and setOnClickListener() to that button.
11(c): define code for setNegetiveButton and setOnClickListener() to that button.
Step 12: Steps to create a emulator
12(a): Got to menu Window → Android Virtual Device Manager
12(b): Select New → Type AVD name and click OK
Step 13: Stop the program

54
411719104053

PROGRAM CODING:
//ALERT
Main_Activity.java
package admin.example.com.alert;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private Button btnSubmitQuiz;


int score,ans1,ans2,ans3,ans4;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
RadioGroup b1=(RadioGroup)findViewById(R.id.answer1);
b1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch(checkedId) {
case R.id.answer1A:
ans1=1;
break;
case R.id.answer1B:
ans1=2;
break;
case R.id.answer1C:
ans1=3;
break;
case R.id.answer1D:
ans1=4;
55
411719104053

break;
}
}
});
RadioGroup b2=(RadioGroup)findViewById(R.id.answer2);
b2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch(checkedId) {
case R.id.answer2A:
ans2=1;
break;
case R.id.answer2B:
ans2=2;
break;
case R.id.answer2C:
ans2=3;
break;
case R.id.answer2D:
ans2=4;
break;
}
}
});
RadioGroup b3=(RadioGroup)findViewById(R.id.answer3);
b3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.answer3A:
ans3 =1;
break;
case R.id.answer3B:
ans3 =2;
break;
case R.id.answer3C:
ans3 =3;
break;
case R.id.answer3D:
ans3 =4;
break;
}
}
});
RadioGroup b4=(RadioGroup)findViewById(R.id.answer4);
56
411719104053

b4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.answer4A:
ans4 =1;
break;
case R.id.answer4B:
ans4 =2;

break;
case R.id.answer4C:
ans4=3;
break;
case R.id.answer4D:
ans4 =4;
break;
}
}
});

btnSubmitQuiz = (Button) findViewById(R.id.submit);


btnSubmitQuiz.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);

// Setting Dialog Title


alertDialog.setTitle("SHOW RESULT");

alertDialog.setMessage("Are you sure you want SUBMIT this?");


// Setting Icon to Dialog
// alertDialog.setIcon(R.drawable.tick);
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {

score =0;
// TODO Auto-generated method stub
if(ans1 == 2)
score++;
if(ans2 == 3)
score++;
if(ans3 == 1)
score++;
57
411719104053

if(ans4 == 4)

58
411719104053

score++;
Toast.makeText(MainActivity.this, "Your score is:" + score + " out of 4.",
Toast.LENGTH_LONG).show();
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke NO event
Toast.makeText(getApplicationContext(), "You clicked NO.CHECK YOUR
ANSWER", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
alertDialog.show(); // Showing Alert Message
}
});
}
}

Activity_main.xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:background="#f2baf2">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*”
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="@+id/Title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical|center_horizontal"
android:text="QUIZ"
android:textSize="25sp"
59
411719104053

android:textStyle="bold" />
<View
android:layout_height="2px"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:background="#DDFFDD"/>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18sp" android:text="1.GSM is" android:layout_span="4"
android:padding="18dip"android:textColor="#121111"/></TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<RadioGroup
android:id="@+id/answer1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4" >
<RadioButton
android:id="@+id/answer1A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#110f0f"
android:text="global science management"
android:checked="false" />
<RadioButton
android:id="@+id/answer1B"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="global system for mobile computing"
android:checked="false" />
<RadioButton
android:id="@+id/answer1C"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Great science master"
android:checked="false" />

60
411719104053

<RadioButton
android:id="@+id/answer1D"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Global system management"
android:checked="false" />
</RadioGroup>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18sp"
android:text="2.Which is NOT the characteristics of Mobile computing"
android:layout_span="4"
android:padding="18dip"
android:textColor="#161416"/></TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<RadioGroup
android:id="@+id/answer2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4" >
<RadioButton
android:id="@+id/answer2A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="broadcast"
android:checked="false" />
<RadioButton
android:id="@+id/answer2B"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="ubiquity"
android:checked="false" />
<RadioButton

61
411719104053

android:id="@+id/answer2C"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="interoperability"
android:checked="false" />
<RadioButton
android:id="@+id/answer2D"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="location awareness"
android:checked="false" />
</RadioGroup>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18sp"
android:text="3.BUS is a" android:layout_span="4"
android:padding="18dip"
android:textColor="#000000"/></TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<RadioGroup
android:id="@+id/answer3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4" >
<RadioButton
android:id="@+id/answer3A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="peer to peer architechture"
android:checked="false" />
<RadioButton
android:id="@+id/answer3B"
android:layout_width="match_parent"
android:layout_height="wrap_content"
62
411719104053

android:textColor="#000000"
android:text="packet forwarding"
android:checked="false" />
<RadioButton
android:id="@+id/answer3C"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="topology which follows round robin "
android:checked="false" />
<RadioButton
android:id="@+id/answer3D"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="none of the above"
android:checked="false" />
</RadioGroup></TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18sp"
android:text="4.which is not a category in fixed assignment scheme"
android:layout_span="4"
android:padding="18dip"
android:textColor="#000000"/></TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<RadioGroup
android:id="@+id/answer4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4" >
<RadioButton
android:id="@+id/answer4A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="FDMA"
android:checked="false" />

63
411719104053

<RadioButton
android:id="@+id/answer4B"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="TDMA"
android:checked="false" />
<RadioButton
android:id="@+id/answer4C"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="CDMA"
android:checked="false" />
<RadioButton
android:id="@+id/answer4D"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="CSMA"
android:checked="false" />
</RadioGroup></TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Submit /></TableRow>
</TableLayout>
</ScrollView>

64
411719104053

OUTPUT:

65
411719104053

RESULT
Thus, the android application that creates alert upon receiving a message has been developed
successfully.

66
411719104053

Ex. No. 10 RSS FEED

Aim
To develop an application that makes use of RSS feed
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Design the required tool in the palette window
3(a):In the activity_main.xml file use the list view to display the courses available
3(b): in rss_list_layout.xml file use the textview components to view the title and the links.
3(c): in main_list_layout.xml file use the textvies for the index and the titles.
3(d):in activity_rss_loader.xml file use the Listview and the process bars
Step 4: create the following java files and write the code in it
4(a):in MainActivity.java create an arrayList for the courses and the rss-path .add the courses
to the ListView and use the MainListAdapter object to handle the events of the listView with the
arguments as the rss_list_layout and the course class.
4(b): Rssloader.java write the code to load the feed from the links to display it in the screen
using the processbar of theActivity_rss_loader
4(c): MainListAdapter.java get the index and the titles and display it on to the screen using
the main_list_layout.
4(d): MainListItemClickListener.java implements the itemclickListener where it gets the
various links from the corresponding rss_path
4(e):in RssReader.java it creates the available RSS item list from the RSS url and parses it
4(f): RssListAdapter.java , RssItemClickListener.java, RssItem.java and
RssParseHandler.java files are used to manage the rss link and when clicked on a particular item the
corresponding feeds are retrieved and displayed to the user.
Step 5:in the AndroidManifest.xml file use the uses-permission xml tag to give the internet
permission.
Step 6: Launch the application using the emulator then go to tools->android->android device
manager->emulator control. Send the location information to the emulator.
Step 7: Stop the program.

67
411719104053

PROGRAM CODING:
//RSS FEED
Main_Activity.java
package com.example.admin.rss;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import java.util.ArrayList;

public class MainActivity extends Activity {


ArrayList<Course> courses = new ArrayList<Course>();
public static String rss_path="http://ocw.mit.edu/rss/new/";
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
courses.add(new Course("Computer science engineering","mit-newcourses-
6.xml"));
courses.add(new Course("Civil engineering", "mit-newcourses-1.xml"));
courses.add(new Course("Mechanical engineering", "mit - newcourses-2.xml"));
courses.add(new Course("Architecture", "mit - newcourses - 4.xml"));
ListView mainList = (ListView) findViewById(R.id.listView);
MainListAdapter adapter = new MainListAdapter(this, R.layout.main_list_layout,
courses);
mainList.setAdapter(adapter);
MainListItemClickListener listener = new MainListItemClickListener(courses, this);
mainList.setOnItemClickListener(listener);
}}
RssLoder.java:
package com.example.admin.rss;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar;

68
411719104053

import android.widget.Toast;
import java.util.ArrayList;
public class RssLoader extends AppCompatActivity {
Activity local;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rss_loader);
local = this;
progressBar = (ProgressBar) findViewById(R.id.progress);
Intent i = getIntent();
//gets the root intent
String title = i.getStringExtra("title");
//gets the String supplied with the tag title
String url = i.getStringExtra("link");
//gets the String supplied with the tag link
getRssData getRssData = new getRssData();
getRssData.execute(url);
//actionbar
getSupportActionBar().setTitle(title);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

private class getRssData extends AsyncTask<String, Void, ArrayList<RssItem>> {


@Override
protected ArrayList<RssItem> doInBackground(String... params) {
try {
RssReader rssReader = new RssReader(params[0]);
//create rss reader
return rssReader.getItems();
//returns items parsed from rss file
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(ArrayList<RssItem> rssItems) {
if (rssItems != null) {
ListView rssList = (ListView) findViewById(R.id.lstRssFeed);
RssListAdapter adapter = new RssListAdapter(local, R.layout.rss_list_layout,
rssItems);

69
411719104053

rssList.setAdapter(adapter);
rssList.setOnItemClickListener(new RssItemClickListener(local, rssItems));
Toast.makeText(local, "Feed Loaded", Toast.LENGTH_SHORT).show();
} else
Toast.makeText(local, "Could not load feed. Check your network
connections.", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.INVISIBLE);
}

@Override
protected void onPreExecute() {
Toast.makeText(local, "Loading Feed", Toast.LENGTH_LONG).show();
}
}
}
MainListAdapter.java:
package com.example.admin.rss;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;

public class MainListAdapter extends ArrayAdapter<Course> {


int layoutResourceId;

Context context;
ArrayList<Course> list;
public MainListAdapter(Context context, int resource, ArrayList<Course> objects) {
super(context, resource, objects);
this.layoutResourceId = resource;
this.context = context;
this.list = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
MainListHolder holder = null;
if (row== null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new MainListHolder();
holder.indexTxt = (TextView) row.findViewById(R.id.txtIndex);
70
411719104053

holder.titleTxt = (TextView) row.findViewById(R.id.txtTitle);


row.setTag(holder);
}
else
holder= (MainListHolder) row.getTag();
Course course = list.get(position);
holder.indexTxt.setText(String.valueOf(position + 1));
holder.titleTxt.setText(course.getTitle());
return row;

}
static class MainListHolder
{
TextView indexTxt,titleTxt;
}
}
MainListItemClickListener.java:
package com.example.admin.rss;

import android.content.Intent;
import android.widget.AdapterView;
import android.view.View;
import android.app.Activity;
import java.util.ArrayList;

public class MainListItemClickListener implements AdapterView.OnItemClickListener{


ArrayList<Course> list;
Activity activity;
public MainListItemClickListener(ArrayList<Course> list,Activity activity)
{
this.list=list;
this.activity=activity;
}
@Override
public void onItemClick(AdapterView<?> parent,View view,int position,long id)
{
Course course=list.get(position);
Intent intent=new Intent(activity,RssLoader.class);
intent.putExtra("title",course.getTitle());
intent.putExtra("link",MainActivity.rss_path+course.getUrl());

activity.startActivity(intent);

}
}
RssReader.java:

71
411719104053

package com.example.admin.rss;

import java.util.ArrayList;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

public class RssReader {


private String rssUrl;
public RssReader(String rssUrl) {
this.rssUrl = rssUrl;
}
public ArrayList<RssItem> getItems() throws Exception {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
RssParseHandler handler = new RssParseHandler();
parser.parse(rssUrl, handler);
return handler.getRssItems();
}}
RssListAdapter.java

package com.example.admin.rss;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.util.ArrayList;

public class RssListAdapter extends ArrayAdapter<RssItem> {


int layoutResourceId;
Context context;
ArrayList<RssItem> list;
public RssListAdapter(Context context, int resource, ArrayList<RssItem> objects) {
super(context, resource, objects);
this.layoutResourceId = resource;
this.context = context;
this.list = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
RssItemHolder holder = null;
if (row== null){
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
72
411719104053

row = inflater.inflate(layoutResourceId, parent,false);


holder = new RssItemHolder();
holder.titleTxt = (TextView)row.findViewById(R.id.txtTitle);
holder.linkTxt = (TextView)row.findViewById(R.id.txtLink);
row.setTag(holder);
}
else
holder = (RssItemHolder)row.getTag();
RssItem item = list.get(position);
holder.titleTxt.setText(item.getTitle());
holder.linkTxt.setText(item.getLink());
return row;
}
static class RssItemHolder {
TextView titleTxt, linkTxt;
}}
RssItemClickListener.java
package com.example.admin.rss;

import android.app.Activity;
import android.content.Intent;
import android.widget.AdapterView;
import java.util.ArrayList;
import android.net.Uri;
import android.view.View;

public class RssItemClickListener implements AdapterView.OnItemClickListener {


Activity activity;
ArrayList<RssItem> list;
public RssItemClickListener(Activity activity, ArrayList<RssItem> list) {
this.activity = activity;
this.list = list;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(list.get(position).getLink()));
activity.startActivity(intent);
}}
RssItem.java
package com.example.admin.rss;

public class RssItem {


private String title, link;
public String getTitle(){
return title;
73
411719205032

}
public void setTitle(String title) {
this.title = title;
}
public String getLink(){
return link;
}
public void setLink(String link)
{
this.link=link;}
}
RssParseHandler.java
package com.example.admin.rss;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.ArrayList;

public class RssParseHandler extends DefaultHandler {


private ArrayList<RssItem> rssItems;
//list to store rss items parsed
private RssItem currentItem;
//stores the currently parsing RssItem
private boolean parsingTitle, parsingLink;
//parsing title/link indicators
public RssParseHandler() {rssItems = new ArrayList<>();
}
public ArrayList<RssItem> getRssItems() {
return rssItems;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if ("item".equals(qName)){
currentItem = new RssItem();
}
//create a new RssItem to store data

else if("title".equals(qName)){
parsingTitle = true;
}
else if("link".equals(qName)){
parsingLink = true;
}
//sets the current item to rss item when parsing item
//sets appropriate indicators to true when opening tags are processed
}
74
411719205032

@Override
public void endElement(String uri, String localName, String qName) throws
SAXException {
if ("item".equals(qName)){
rssItems.add(currentItem);
currentItem = null;
}
else if ("title".equals(qName)){
parsingTitle = false;
}
else if ("link".equals(qName)){
parsingLink = false;
}
//adds the current item to list
//sets appropriate indicators to false when closing tags are processed
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (parsingTitle){
if (currentItem!= null) {
currentItem.setTitle(new String(ch, start, length));
//sets titleof the currentitem
}
}
else if (parsingLink){
if (currentItem != null) {
currentItem.setLink(new String(ch, start, length));
}}}}

Course.java:
package com.example.admin.rss;

public class Course {


private String title,url;
public Course(String title,String url)
{
this.title=title;
this.url=url;
}
public String getTitle()
{
return title;

}
public String getUrl()
{
return url;
}
75
411719205032

}
76
411719205032

AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.rss">
<uses-permission android:name="android.permission.INTERNET"/>
<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"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<activity android:name=".RssLoader" android:parentActivityName=".MainActivity"/>
</application>

</manifest>
activity_rss_loader.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:layout_width="339dp"
android:layout_height="260dp"
android:id="@+id/lstRssFeed"
android:layout_gravity="center_horizontal" />

<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="246dp"
android:layout_height="match_parent"
android:id="@+id/progress"
android:indeterminate="false" />
</LinearLayout>

77
411719205032

main_list_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">

<TextView
android:layout_width="176dp"
android:layout_height="wrap_content"
android:text="INDEX"
android:id="@+id/txtIndex"
android:layout_gravity="center_horizontal" />

<TextView
android:layout_width="138dp"
android:layout_height="0dp"
android:text="TITLE"
android:id="@+id/txtTitle"
android:layout_gravity="center_horizontal"
android:layout_weight="0.09" />
</LinearLayout>
rss_list_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TITLE"
android:id="@+id/txtTitle" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="&quot;http://www.example.com/post1&quot;"
android:id="@+id/txtLink" />
</LinearLayout>
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
78
411719205032

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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.admin.rss.MainActivity"
tools:showIn="@layout/activity_main">

<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="43dp" />

</RelativeLayout>

79
411719205032

OUTPUT:

RESULT
Thus, the mobile application that makes use of RSS feed has been developed successfully.
80
411719205032

EX NO:11 EMAIL APPLICATION


Aim
To develop an application that sends an Email.
Algorithm

Creating a New project:


1. Open Android Studio and then click on File -> New -> New project.
2. Then type the Application name as “exno11″ and click Next.
3. Then select the Minimum SDK as shown below and click Next.
4. Then select the Empty Activity and click Next.
5. Finally click Finish.
6. It will take some time to build and load the project.

Designing layout for the Android Application:


• Click on app -> res -> layout -> activity_main.xml.
• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingLeft="20dp" android:paddingRight="20dp" android:orientation="vertical" >
<EditText android:id="@+id/txtTo"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:hint="To"/>
<EditText android:id="@+id/txtSub"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="Subject"/>
<EditText>
android:id="@+id/txtMsg" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_weight="1" android:gravity="top"
android:hint="Message"/>
<Button android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_gravity="right" android:text="Send"
android:id="@+id/btnSend"/>
</LinearLayout>

81
411719205032

Adding permissions in Manifest for the Android Application:


• Click on app -> manifests -> AndroidManifest.xml.
• Now include the INTERNET permissions in the AndroidManifest.xml file as shown below.
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="com.example.exno11" >
<uses-permission android:name="android.permission.INTERNET" />
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="com.example.exno11.MainActivity"
android:label="@string/app_name">
<intent-filter><action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="message/rfc822"/>
</intent-filter>
</activity>
</application>
</manifest>
• So now the Permissions are added in the Manifest.

Java Coding for the Android Application:


• Click on app -> java -> com.example.exno10 -> MainActivity.
• Then delete the code which is there and type the code as given below.
MainActivity.java:
package com.example.Email;
import android.content.Intent;
//import android.support.v7.app.AppCompatActivity
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity
public class MainActivity extends AppCompatActivity {
private EditText eTo; private EditText eSubject; private EditText eMsg; private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eTo = (EditText)findViewById(R.id.txtTo);
eSubject = (EditText)findViewById(R.id.txtSub);
eMsg = (EditText)findViewById(R.id.txtMsg); btn = (Button)findViewById(R.id.btnSend);
btn.setOnClickListener(new View.OnClickListener() { @Override
82
411719205032

public void onClick(View v) {


Intent it = new Intent(Intent.ACTION_SEND); it.putExtra(Intent.EXTRA_EMAIL, new
String[]{eTo.getText().toString()});
it.putExtra(Intent.EXTRA_SUBJECT,eSubject.getText().toString());
it.putExtra(Intent.EXTRA_TEXT,eMsg.getText()); it.setType("message/rfc822");
startActivity(Intent.createChooser(it,"Choose Mail App"));
}
});
}

83
411719205032

OUTPUT:

Result:
Thus Android Application for sending an email is developed and executed successfully
84
411719205032

Ex. No. 12 DEVELOP A MOBILE APPLICATION FOR SIMPLE NEEDS


(MINI PROJECT)

A NATIVE CALCULATOR APPLICATION

Aim
To develop a native calculator application.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
4(a):insert buttons for digits 0 to 9 and buttons for all the operators such as +,-,*,/,= and also
a button for clearing the plaintext field
4(b): insert plaintext for the input arithmetic expression
Step 5: Use F2 key to edit the name of the tools
Step 6: Open MainActivity.java file and type the code inside the class
6(a): set OnClickListener() method for each buttons to perform the function of that button

6(b): if the button is any operator perform the specified arithmetic operation on the inputs
given
6(c):display the computed output on the plain textfield
Step 7: Steps to create a emulator
7 (a): Got to menu Window → Android Virtual Device Manager
7(b): Select New → Type AVD name and click OK
Step 8: Stop the program

85
411719205032

PROGRAM CODING
//A NATIVE CALCULATOR APPLICATION

MainActivity.java
package com.example.admin.cal_harsh;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


Button nine,eig,sev,six,fiv,four,thr,two,one,zero,dot,plus,min,div,mul,eql,clr;
EditText et;
String s="0";
String inDigit;
double result=0;
char Io=' ';
int ch;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nine=(Button)findViewById(R.id.b9);
eig=(Button)findViewById(R.id.b8);
sev=(Button)findViewById(R.id.b7);
six=(Button)findViewById(R.id.b6);
fiv=(Button)findViewById(R.id.b5);
four=(Button)findViewById(R.id.b4);
thr=(Button)findViewById(R.id.b3);
two=(Button)findViewById(R.id.b2);
one=(Button)findViewById(R.id.b1);
zero=(Button)findViewById(R.id.b0);
dot=(Button)findViewById(R.id.bdot);
plus=(Button)findViewById(R.id.bplus);
min=(Button)findViewById(R.id.bsub);
div=(Button)findViewById(R.id.bdiv);
mul=(Button)findViewById(R.id.bmul);
eql=(Button)findViewById(R.id.beql);
clr=(Button)findViewById(R.id.bclr);
et=(EditText)findViewById(R.id.editText);
nine.setOnClickListener(this);
eig.setOnClickListener(this);
sev.setOnClickListener(this);
six.setOnClickListener(this);
fiv.setOnClickListener(this);
four.setOnClickListener(this);
thr.setOnClickListener(this);
two.setOnClickListener(this);

86
411719205032

one.setOnClickListener(this);
dot.setOnClickListener(this);
plus.setOnClickListener(this);
min.setOnClickListener(this);
div.setOnClickListener(this);
mul.setOnClickListener(this);
eql.setOnClickListener(this);
clr.setOnClickListener(this);
et.setOnClickListener(this);

}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.b0:
case R.id.b1:
case R.id.b2:
case R.id.b3:
case R.id.b4:
case R.id.b5:
case R.id.b6:
case R.id.b7:
case R.id.b8:
case R.id.b9:
case R.id.bdot:
inDigit = ((Button) v).getText().toString();
if (s.equals("0")) {
s = inDigit;
} else {
s += inDigit;
}
et.setText(s);
if (Io == '=') {
result = 0;
Io = ' ';
}
break;
case R.id.bplus:
compute();
Io = '+';
break;
case R.id.bsub:
compute();
Io = '-';
break;
case R.id.bmul:
compute();
Io = '*';
break;
case R.id.bdiv:
compute();
Io = '/';
break;
case R.id.beql:
87
411719205032

compute();
Io = '=';
break;
case R.id.bclr:
result = 0;
s = "0";
Io = ' ';
et.setText("0");
break;
}
}

private void compute() {


double inNum=Double.parseDouble(s);
s="0";
if(Io==' ')
{
result=inNum;
}
else if(Io=='+')
{
result+=inNum;
}
else if(Io=='-')
{
result-=inNum;
}
else if(Io=='*')
{
result*=inNum;
}
else if(Io=='/')
{
result/=inNum;
}
else if(Io=='=')
{

}
et.setText(String.valueOf(result));
}

88
411719205032

Activity_main.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"
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="com.example.admin.cal_harsh.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="calculator"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="@+id/textView" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_marginTop="40dp"
android:text=" "
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="@+id/b0"
android:layout_marginTop="69dp"
android:layout_below="@+id/editText"
android:layout_toLeftOf="@+id/bdiv"
android:layout_toStartOf="@+id/bdiv" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/b1"
android:layout_alignTop="@+id/b0"
89
411719205032

android:layout_alignRight="@+id/textView"
android:layout_alignEnd="@+id/textView" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/b2"
android:layout_alignTop="@+id/b1"
android:layout_toRightOf="@+id/b1"
android:layout_toEndOf="@+id/b1" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="@+id/b4"
android:layout_alignTop="@+id/button"
android:layout_toLeftOf="@+id/b5"
android:layout_toStartOf="@+id/b5" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/b5"
android:layout_alignTop="@+id/b4"
android:layout_alignLeft="@+id/b1"
android:layout_alignStart="@+id/b1" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="@+id/b6"
android:layout_alignTop="@+id/b5"
android:layout_toRightOf="@+id/b5"
android:layout_toEndOf="@+id/b5" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/b7"
android:layout_below="@+id/b4"

90
411719205032

android:layout_alignLeft="@+id/b4"
android:layout_alignStart="@+id/b4" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/b8"
android:layout_alignTop="@+id/b7"
android:layout_toRightOf="@+id/b7"
android:layout_toEndOf="@+id/b7" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/b9"
android:layout_alignBottom="@+id/b8"
android:layout_toRightOf="@+id/b8"
android:layout_toEndOf="@+id/b8" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="clr"
android:id="@+id/bclr"
android:layout_below="@+id/b7"
android:layout_alignLeft="@+id/b7"
android:layout_alignStart="@+id/b7" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:id="@+id/bplus"
android:layout_below="@+id/b8"
android:layout_alignLeft="@+id/b5"
android:layout_alignStart="@+id/b5" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:id="@+id/bsub"
android:layout_below="@+id/b9"

91
411719205032

android:layout_toRightOf="@+id/bplus"
android:layout_toEndOf="@+id/bplus" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_below="@+id/b2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="442dp"
android:layout_marginStart="442dp" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*"
android:id="@+id/bmul"
android:layout_below="@+id/bclr"
android:layout_alignLeft="@+id/bclr"
android:layout_alignStart="@+id/bclr" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="@+id/bdiv"
android:layout_above="@+id/beql"
android:layout_toRightOf="@+id/bmul"
android:layout_toEndOf="@+id/bmul" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="."
android:id="@+id/bdot"
android:layout_alignTop="@+id/bdiv"
android:layout_toRightOf="@+id/bdiv"
android:layout_toEndOf="@+id/bdiv" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="="

92
411719205032

android:id="@+id/beql"
android:layout_below="@+id/bmul"
android:layout_toRightOf="@+id/bmul"
android:layout_toEndOf="@+id/bmul" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/b3"
android:layout_above="@+id/b6"
android:layout_toRightOf="@+id/b2"
android:layout_toEndOf="@+id/b2" />
</RelativeLayout>

93
411719205032

OUTPUT
Expression:8*4=32

RESULT
Thus, the mobile application for a native calculator has been developed successfully.

94

You might also like