Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
224 views

Mad Lab Record

The document describes the development of a mobile application that uses GUI components, font, and colors. It details the steps to create a new Android project, design the layout, and write Java code to change the text size and color on button clicks. When run, the application demonstrates changing font size and cycling through different text colors.

Uploaded by

vamsi
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
224 views

Mad Lab Record

The document describes the development of a mobile application that uses GUI components, font, and colors. It details the steps to create a new Android project, design the layout, and write Java code to change the text size and color on button clicks. When run, the application demonstrates changing font size and cycling through different text colors.

Uploaded by

vamsi
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 95

PANIMALAR ENGINEERING COLLEGE

1
(A CHRISITIAN MINORITY INSTITUTION)
JAISAKTHI EDUCATIONAL TRUST
ACCREDITED BY NATIONAL BOARD OF ACCREDITATION (NBA)

Bangalore Trunk Road, Varadharajapuram, Nazarathpettai,


Poonamallee, Chennai – 600 123

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CS8662 – MOBILE APPLICATION DEVELOPMENT LABORATORY

III CSE - VI SEMESTER

2
PANIMALAR ENGINEERING COLLEGE
(A CHRISITIAN MINORITY INSTITUTION)
JAISAKTHI EDUCATIONAL TRUST
ACCREDITED BY NATIONAL BOARD OF ACCREDITATION - NBA, NEW DELHI
Bangalore Trunk Road, Varadharajapuram, Nazarathpettai,
Poonamallee, Chennai – 600 123

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

BONAFIDE CERTIFICATE
This is a Certified Bonafide Record Book of

Mr. /Ms. ………………..VAMSI KRISHNA . J ………………………

Register Number ………………..211418104301………………………...

Submitted for Anna University Practical Examination held on …07/08/2021… in

CS8662 – MOBILE APPLICATION DEVELOPMENT Laboratory during JUNE

- 2021.

Staff – In charge

External Examiner Internal Examiner

3
INDEX

Ex Page
Date Title Marks Sign
No No
Develop an Application that uses GUI Components, Font and
01. 20/2/21 1
Colours.
Develop an Application that uses Layout Managers and Event
02. 27/2/21 10
Listeners.
Write an Application that Draws Basic Graphical Primitives
03. 06/3/21 15
on the Screen.

04. 13/3/21 Develop an Application that makes use of Databases. 18

Develop an Application that makes use of Notification


05. 20/3/21 25
Manager.

06. 27/3/21 Implement an Application that uses Multi-Threading. 30

Develop a Native Application that uses GPS Location


07. 03/4/21 35
Information

08. 10/4/21 Implement an Application that Writes Data to the SD Card. 39

Implement an Application that Creates an Alert Upon


09. 17/4/21 46
Receiving a Message.

10. 24/4/21 Write a Mobile Application that makes use of RSS Feed. 50

11. 8/5/21 Develop a Mobile Application to send an E-Mail. 60

ADDITIONAL EXPERIMENTS

12. 15/5/21 Develop a Native Application for Calculator 68

13. 22/5/21 Develop a Application that creates Alarm Clock 79

4
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


Date: 20/2/21 MOBILE APPLICATIONS USING
Ex. No: 01 GUI COMPONENTS, FONT AND COLOURS

AIM
To develop a Simple Android Application that uses GUI components, Font and Colors.

PROCEDURE

Creating a New project:


 Open Android Studio and then click on File -> New -> New project.

 Then type the Application name as “ex.no.1″ and click Next.

1
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 Then select the Minimum SDK as shown below and click Next.

 Then select the Empty Activity and click Next.


2
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 Finally click Finish.

 It will take some time to build and load the project.


 After completion it will look as given below.
3
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

Designing layout for the Android Application:


 Click on app -> res -> layout -> activity_main.xml.

 Now click on Text as shown below.

4
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 Then delete the code which is there and type the code as given below.
Activity_main.xml:
Now click on Design and your application will look as given below.

 So now the designing part is completed.

5
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


Java Coding for the Android Application:
 Click on app -> java -> com.example.exno1 -> MainActivity.

 Then delete the code which is there and type the code as given below.
PROGRAM
MainActivity.java:
package com.example.exno1;
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
{
    int ch=1;
    float font=30;

6
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final TextView t= (TextView) findViewById(R.id.textView);
        Button b1= (Button) findViewById(R.id.button1);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                t.setTextSize(font);
                font = font + 5;
                if (font == 50)
                    font = 30;
            }
        });
        Button b2= (Button) findViewById(R.id.button2);
        b2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (ch) {
                    case 1:
                        t.setTextColor(Color.RED);
                        break;
                    case 2:
                        t.setTextColor(Color.GREEN);
                        break;

7
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


                    case 3:
                        t.setTextColor(Color.BLUE);
                        break;
                    case 4:
                        t.setTextColor(Color.CYAN);
                        break;
                    case 5:
                        t.setTextColor(Color.YELLOW);
                        break;
                    case 6:
                        t.setTextColor(Color.MAGENTA);
                        break;
                }
                ch++;
                if (ch == 7)
                    ch = 1;
            }
        });
    }
}
So now the Coding part is also completed.

Now run the application to see the output.

8
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


OUTPUT

     

    

RESULT
Thus the program for developing an Application that uses GUI Components, Font and Colours is
done using java with Android Studio and output is verified successfully.
Date: 27/2/21 MOBILE APPLICATIONS USING

9
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


Ex. No: 02 LAYOUT MANAGERS AND EVENT LISTENERS

AIM
To develop a Simple Android Application that uses Layout Managers and Event Listeners.

PROCEDURE
Creating a New project:
 Open Android Studio and then click on File -> New -> New project.

 Then type the Application name as “ex.no.2″ and click Next

 Then select the Minimum SDK as shown below and click Next.

 Then select the Empty Activity and click Next.

 Finally click Finish.

Designing layout for the Android Application:

Designing Layout for Main Activity:


 Click on app -> res -> layout -> activity_main.xml.

 So now the designing part of Main Activity is completed.

10
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


Designing Layout for Second Activity:
 Click on app -> res -> layout -> activity_second.xml.

 So now the designing part of Second Activity is also completed.

PROGRAM

Main Activity.java: (Click on app -> java -> com.example.exno2 -> MainActivity.)
package com.example.exno2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
public class MainActivity extends AppCompatActivity {
 
11
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


  EditText e1,e2;
    Button bt;
    Spinner s;
    String [] dept_array={"CSE","ECE","IT","Mech","Civil"};
     String name,reg,dept;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        e1= (EditText) findViewById(R.id.editText);
        e2= (EditText) findViewById(R.id.editText2);
        bt= (Button) findViewById(R.id.button);
        s= (Spinner) findViewById(R.id.spinner);
        ArrayAdapter adapter= new
ArrayAdapter(MainActivity.this,android.R.layout.simple_spinner_item,dept_array);
        s.setAdapter(adapter);
         bt.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v)
{
                //Getting the Values from Views(Edittext & Spinner)
                name=e1.getText().toString();
                reg=e2.getText().toString();
                dept=s.getSelectedItem().toString();
                //Intent For Navigating to Second Activity
                Intent i = new Intent(MainActivity.this,SecondActivity.class);
                //For Passing the Values to Second Activity
                i.putExtra("name_key", name);
                i.putExtra("reg_key",reg);
                i.putExtra("dept_key", dept);
12
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


                startActivity(i);
            }
        }); }}

Second Activity.java: (Click on app -> java -> com.example.exno2 -> SecondActivity.)
package com.example.exno2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class SecondActivity extends AppCompatActivity
{
    TextView t1,t2,t3;
    String name,reg,dept;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        t1= (TextView) findViewById(R.id.textView1);
        t2= (TextView) findViewById(R.id.textView2);
        t3= (TextView) findViewById(R.id.textView3);
        //Getting the Intent
        Intent i = getIntent();
        //Getting the Values from First Activity using the Intent received
        name=i.getStringExtra("name_key");
        reg=i.getStringExtra("reg_key");
        dept=i.getStringExtra("dept_key");
        //Setting the Values to Intent
        t1.setText(name);

13
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


        t2.setText(reg);
        t3.setText(dept);
    }
}
So now the Coding part of Second Activity is also completed.
Now run the application to see the output.
OUTPUT

                 

RESULT
Thus the program for developing an Application that uses Layout Mangers and Event
Listeners is done using java with Android Studio and output is verified successfully.
Date: 06/3/21 MOBILE APPLICATIONS USING
Ex. No: 03 BASIC GRAPHICAL PRIMITIVES ON THE SCREEN

14
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


AIM
To develop a Simple Android Application that draws basic Graphical Primitives on the screen.

PROCEDURE
Creating a New project:
 Open Android Studio and then click on File -> New -> New project.

 Then type the Application name as "ex.no.3" and click Next

 Then select the Minimum SDK as shown below and click Next.

 Then select the Empty Activity and click Next.

 Finally click Finish.

Designing layout for the Android Application:

Designing Layout for Main Activity:


 Click on app -> res -> layout -> activity_main.xml.

 So now the designing part of Main Activity is completed.

15
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


Java Coding for the Android Application

Click on app -> java -> com.example.exno3 -> MainActivity.

PROGRAM

MainActivity.java:
package com.example.exno3;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        //Creating a Bitmap
        Bitmap bg = Bitmap.createBitmap(720, 1280, Bitmap.Config.ARGB_8888);
 
        //Setting the Bitmap as background for the ImageView
        ImageView i = (ImageView) findViewById(R.id.imageView);
        i.setBackgroundDrawable(new BitmapDrawable(bg));
i.setImageDrawable(null);
 
        //Creating the Canvas Object
        Canvas canvas = new Canvas(bg);
 
        //Creating the Paint Object and set its color & TextSize
        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        paint.setTextSize(50);
 
        //To draw a Rectangle
        canvas.drawText("Rectangle", 420, 150, paint);
        canvas.drawRect(400, 200, 650, 700, paint);
 

16
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


        //To draw a Circle
        canvas.drawText("Circle", 120, 150, paint);
canvas.drawCircle(200, 350, 150, paint);
 
        //To draw a Square
        canvas.drawText("Square", 120, 800, paint);
        canvas.drawRect(50, 850, 350, 1150, paint);
 
        //To draw a Line
        canvas.drawText("Line", 480, 800, paint);
        canvas.drawLine(520, 850, 520, 1150, paint);
    }
}
OUTPUT

RESULT
Thus the program for developing an Application that draws Basic Graphical Primitives on the Screen
is done using Java with Android Studio and output is verified successfully.
Date: 13/3/21
MOBILE APPLICATIONS DATABASE
Ex. No: 04

17
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


AIM

To develop an application that makes use of database.

PROCEDURE

Creating a New project:

 Open Android Studio and then click on File -> New -> New project.

 Then type the Application name as "ex.no.4"and click Next

 Then select the Minimum SDK as shown below and click Next.

 Then select the Empty Activity and click Next.

 Finally click Finish.


Designing layout for the Android Application:

Designing Layout for Main Activity:


 Click on app -> res -> layout -> activity_main.xml.

 So now the designing part of Main Activity is completed.


Java Coding for the Android Application

Click on app -> java -> com.example.exno4 -> MainActivity.

PROGRAM

18
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


MainActivity.java

import android.app.Activity;
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;
public class MainActivity extends Activity implements OnClickListener
{EditText Rollno,Name,Mark
Button Insert,Delete,Update,View,ViewAll
SQLiteDatabase db;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Rollno=(EditText)findViewById(R.id.Rollno);
Name=(EditText)findViewById(R.id.Name);
Marks=(EditText)findViewById(R.id.Marks);
Insert=(Button)findViewById(R.id.Insert);
Delete=(Button)findViewById(R.id.Delete);
Update=(Button)findViewById(R.id.Update);
View=(Button)findViewById(R.id.View);
ViewAll=(Button)findViewById(R.id.ViewAll);
Insert.setOnClickListener(this);
Delete.setOnClickListener(this);
Update.setOnClickListener(this);
View.setOnClickListener(this);
ViewAll.setOnClickListener(this);

// Creating database and table


db=openOrCreateDatabase("StudentDB1", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,name
VARCHAR,marks VARCHAR,primary key(rollno));");
}
public void onClick(View view)
{
// Inserting a record to the Student table
if(view==Insert)
19
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


{
// Checking for empty fields
if(Rollno.getText().toString().trim().length()==0||
Name.getText().toString().trim().length()==0||
Marks.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter all values");
return;
}
db.execSQL("INSERT INTO student VALUES('"+Rollno.getText()+"','"+Name.getText()+
"','"+Marks.getText()+"');");
showMessage("Success", "Record added");
clearText();
db.execSQL("INSERT INTO student VALUES('"+Rollno.getText()+"','"+Name.getText()
+"','"+Marks.getText()+"')");
}
// Deleting a record from the Student table
if(view==Delete)
{

if(Rollno.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE rollno='"+Rollno.getText()+"'",
null);
if(c.moveToFirst())
{
db.execSQL("DELETE FROM student WHERE rollno='"+Rollno.getText()+"'");
showMessage("Success", "Record Deleted");
}
else
{
showMessage("Error", "Invalid Rollno");
}
clearText();
}
// Updating a record in the Student table
if(view==Update)
{

if(Rollno.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
20
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE rollno='"+Rollno.getText()+"'",
null);
if(c.moveToFirst()) {
db.execSQL("UPDATE student SET name='" + Name.getText() + "',marks='" +
Marks.getText() +
"' WHERE rollno='"+Rollno.getText()+"'");
showMessage("Success", "Record Modified");
}
else {
showMessage("Error", "Invalid Rollno");
}
clearText();
}
// Display a record from the Student table
if(view==View)
{
// Checking for empty roll number
if(Rollno.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE rollno='"+Rollno.getText()+"'",
null);
if(c.moveToFirst())
{
Name.setText(c.getString(1));
Marks.setText(c.getString(2));
}
else
{
showMessage("Error", "Invalid Rollno");
clearText();
}
}
// Displaying all the records
if(view==ViewAll)
{
Cursor c=db.rawQuery("SELECT * FROM student", null);
if(c.getCount()==0)
{
showMessage("Error", "No records found");
return;
21
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("Rollno: "+c.getString(0)+"\n");
buffer.append("Name: "+c.getString(1)+"\n");
buffer.append("Marks: "+c.getString(2)+"\n\n");
}
showMessage("Student Details", buffer.toString());
}
}
public void showMessage(String title,String message)
{
Builder builder=new Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}
public void clearText()
{
Rollno.setText("");
Name.setText("");
Marks.setText("");
Rollno.requestFocus();
}
}

OUTPUT

22
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

23
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

RESULT
Thus the program for developing an Application that makes use of Databases is done using Java with
Android Studio and output is verified successfully.
Date: 20/3/21 MOBILE APPLICATIONS USING NOTIFICATION MANAGER

24
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


Ex. No: 05

AIM
 To develop a android application that makes use of notification manager.
PROCEDURE
Creating a New project:
 Open Android Studio and then click on File -> New -> New project.

 Then type the Application name as "ex.no.5" and click Next

 Then select the Minimum SDK as shown below and click Next.

 Then select the Empty Activity and click Next.

 Finally click Finish.

Designing layout for the Android Application:


Click on app -> res -> layout -> activity_main.xml.

 Now click on Text as shown below.

25
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 Then delete the code which is there and type the code as given below.

 Now click on Design and your application will look as given below.

 So now the designing part is completed.

Java Coding for the Android Application:


 Click on app -> java -> com.example.exno5-> Main Activity.

26
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 Then delete the code which is there and type the code as given below.

PROGRAM
MainActivity.java:
package com.example.exno5;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity


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

notify= (Button) findViewById(R.id.button);


e= (EditText) findViewById(R.id.editText);

27
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


notify.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
PendingIntent pending = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
Notification noti = new Notification.Builder(MainActivity.this).setContentTitle("New
Message").setContentText(e.getText().toString()).setSmallIcon(R.mipmap.ic_launcher).setContentIn
tent(pending).build();
NotificationManager manager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
manager.notify(0, noti);
}
});
}
}
So now the Coding part is also completed.

Now run the application to see the output.

OUTPUT

28
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

RESULT
Thus the program for developing an Application that makes use of Notification Manager is
done using Java with Android Studio and output is verified successfully.

29
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


Date: 27/3/21
MOBILE APPLICATION USING MULTI-THREADING
Ex. No: 06

AIM
To develop an Android Application that implements Multi threading.
PROCEDURE
Creating a New project:

 Open Android Studio and then click on File -> New -> New project.

 Then type the Application name as "ex.no.6" and click Next

 Then select the Minimum SDK as shown below and click Next.

 Then select the Empty Activity and click Next.

 Finally click Finish.


Designing layout for the Android Application:
Designing Layout for Main Activity:

 Click on app -> res -> layout -> activity_main.xml.

 So now the designing part of Main Activity is completed.

30
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


Java Coding for the Android Application

 Click on app -> java -> com.example.exno6 -> MainActivity.


PROGRAM
MainActivity.java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity
{
EditText t1,t2;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1=findViewById(R.id.editText3);
t2=findViewById(R.id.editText4);
b1=findViewById(R.id.button2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {

31
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


new Thread(new Runnable() {
@Override
public void run() {
for (int i = 1; i <= 10; i++) {
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
t1.setText(t1.getText().toString() + "1");
}
});
Thread.sleep(100);
} catch (Exception ex) {
}
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 1; i <= 10; i++) {
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
t2.setText(t2.getText().toString() + "2");

32
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


}
});
Thread.sleep(100);
} catch (Exception ex) {
}}}
}).start();
} catch (Exception ex) {
}}
});
}}

OUTPUT

33
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

RESULT
Thus the program for developing an Application that uses Multi-Threading is done using
Java with Android Studio and output is verified successfully.

34
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


Date: 03/4/21 MOBILE APPLICATIONS USING GPS LOCATION
Ex. No: 07 INFORMATION

AIM

To design and develop a mobile application which uses the GPS functionalities of a
Mobile Application Development Framework.
PROCEDURE

Creating a New project:


 Open Android Studio and then click on File -> New -> New project.

 Then type the Application name as "ex.no.7″ and click Next

 Then select the Minimum SDK as shown below and click Next.

 Then select the Empty Activity and click Next.

 Finally click Finish.

Designing layout for the Android Application:

Designing Layout for Main Activity:


 Click on app -> res -> layout -> activity_main.xml.

 So now the designing part of Main Activity is completed.


Java Coding for the Android Application
35
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


 Click on app -> java -> com.example.exno7 -> MainActivity.
PROGRAM
MainActivity.java
package com.example.gps;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {

EditText edtLongitude, edtLatitude;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtLongitude = (EditText)findViewById(R.id.editText1);
edtLatitude = (EditText)findViewById(R.id.editText2);
LocationManager mlocManager =
(LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
mlocListener);

36
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public class MyLocationListener implements LocationListener
{
public void onLocationChanged(Location loc)
{
edtLongitude.setText(String.valueOf(loc.getLongitude()));
edtLatitude.setText(String.valueOf(loc.getLatitude()));
}

public void onProviderDisabled(String provider)


{
Toast.makeText(getApplicationContext(), "Gps disabled",
Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String provider)
{
Toast.makeText(getApplicationContext(), "Gps enabled",
Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras)
{

37
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


}
}
}

OUTPUT

RESULT
Thus the program for developing an Application that uses GPS Location Information is done using
Java with Android Studio and output is verified successfully.
Date: 10/4/21
MOBILE APPLICATION THAT WRITES DATA TO THE SD CARD
Ex. No: 08

AIM

38
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


To develop an Android Application that writes data to the SD Card.
PROCEDURE
Creating a New project:
 Open Android Studio and then click on File -> New -> New project.
 Then type the Application name as "ex.no.8″ and click Next
 Then select the Minimum SDK as shown below and click Next.
 Then select the Empty Activity and click Next.
 Finally click Finish.

Designing layout for the Android Application:

Designing Layout for Main Activity:


 Click on app -> res -> layout -> activity_main.xml.

 So now the designing part of Main Activity is completed.


Providing permission to store a file in the SD Card Location for our Android Application:
 Click on app -> manifests -> AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.exno8" >
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
39
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


</uses-permission>
     <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity android:name=".MainActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Java Coding for the Android Application


 Click on app -> java -> com.example.exno8-> MainActivity.

PROGRAM
MainActivity.java:
package com.example.myapplication_sd;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
40
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


import android.widget.EditText;
import android.widget.Toast;
import java.io.*;
public class MainActivity extends AppCompatActivity
{
EditText e1;
Button write,read,clear;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1= (EditText) findViewById(R.id.editText);
write= (Button) findViewById(R.id.button);
read= (Button) findViewById(R.id.button2);
clear= (Button) findViewById(R.id.button3);
write.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
try
{
FileOutputStream fout=new FileOutputStream("/sdcard/myfile.txt");

fout.write(e1.getText().toString().getBytes());
fout.close();

41
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


Toast.makeText(getBaseContext(),"Data Written in
SDCARD",Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).show();
}
}
});
read.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String message;
// int a;
try
{
FileInputStream fin=new FileInputStream("/sdcard/myfile.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fin));
while ((message = br.readLine()) != null)
{
e1.setText(e1.getText().toString()+message);
}
br.close();
fin.close();
Toast.makeText(getBaseContext(),"Data Recived from
SDCARD",Toast.LENGTH_LONG).show();
42
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


}
catch (Exception e)
{
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
clear.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
e1.setText("");
}
});
}
}

OUTPUT

43
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

44
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

RESULT
Thus the program for developing an Application that writes data to SD Card is done using Java with
Android Studio and output is verified successfully.
Date: 17/4/21 MOBILE APPLICATION THAT CREATES AN ALERT UPON A
Ex. No: 09 MESSAGE

AIM
To develop an Android Application that writes data to the SD Card.

45
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


PROCEDURE
Creating a New project:
 Open Android Studio and then click on File -> New -> New project.

 Then type the Application name as "ex.no.9″ and click Next

 Then select the Minimum SDK as shown below and click Next.

 Then select the Empty Activity and click Next.

 Finally click Finish.

Designing layout for the Android Application:

Designing Layout for Main Activity:


 Click on app -> res -> layout -> activity_main.xml.

 So now the designing part of Main Activity is completed.


Java Coding for the Android Application

 Click on app -> java -> com.example.exno9 -> MainActivity.


PROGRAM
MainActivity.java
package com.example.myapplication_alert;

import android.content.DialogInterface;
46
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


import androidx.appcompat.app.AlertDialog;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

@Override

public void onBackPressed()

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

builder.setMessage("Do you want to exit ?");

builder.setTitle("Alert !");

builder.setCancelable(false);

builder.setPositiveButton("yes", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

finish();

47
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


});

builder.setNegativeButton("no", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog.cancel();

});

AlertDialog alertDialog = builder.create();

alertDialog.show();

OUTPUT

48
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

RESULT
Thus the program for developing an Application that creates an Alert Upon Receiving a
Message is done using Java with Android Studio and output is verified successfully.

Date: 24/4/21
MOBILE APPLICATION THAT MAKES USE OF RSS FEED
Ex. No: 10

AIM

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

PROCEDURE

Creating a New project:

49
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


 Open Android Studio and then click on File -> New -> New project.
 Then type the Application name as “ex.no.10″ and click Next.
 Then select the Minimum SDK as shown below and click Next.
 Then select the Empty Activity and click Next.
 Finally click Finish.

Designing layout for the Android Application:

Designing Layout for Main Activity:

 Click on app -> res -> layout -> activity_main.xml.

 So now the designing part of Main Activity is completed.

Creating Second Activity for the Android Application:

 Click on File -> New -> Activity -> Empty Activity.

50
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

Adding permissions in Manifest for the Android Application:

 Click on app -> manifests -> AndroidManifest.xml


AndroidManifest.xml:

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.exno6" >

<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" >

51
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


<activity android:name=".MainActivity" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

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

</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.
PROGRAM
MainActivity.java

package com.example.myapplication_ex10;

52
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


import android.app.ListActivity;

import android.content.Intent;

import android.net.Uri;

import android.os.AsyncTask;

import android.os.Bundle;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import org.xmlpull.v1.XmlPullParser;

import org.xmlpull.v1.XmlPullParserException;

import org.xmlpull.v1.XmlPullParserFactory;

import java.io.IOException;

import java.io.InputStream;

import java.net.MalformedURLException;

import java.net.URL;

import java.util.ArrayList;

import java.util.List;

public class MainActivity extends ListActivity

List headlines;

List links;

@Override
53
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

new MyAsyncTask().execute();

class MyAsyncTask extends AsyncTask<Object,Void,ArrayAdapter>

@Override

protected ArrayAdapter doInBackground(Object[] params)

headlines = new ArrayList();

links = new ArrayList();

try

URL url = new URL("https://codingconnect.net/feed");

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

factory.setNamespaceAware(false);

XmlPullParser xpp = factory.newPullParser();

// We will get the XML from an input stream

xpp.setInput(getInputStream(url), "UTF_8");

boolean insideItem = false;

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


54
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


int eventType = xpp.getEventType();

while (eventType != XmlPullParser.END_DOCUMENT)

if (eventType == XmlPullParser.START_TAG)

if (xpp.getName().equalsIgnoreCase("item"))

insideItem = true;

else if (xpp.getName().equalsIgnoreCase("title"))

if (insideItem)

headlines.add(xpp.nextText()); //extract the headline

else if (xpp.getName().equalsIgnoreCase("link"))

if (insideItem)

links.add(xpp.nextText()); //extract the link of article

else if(eventType==XmlPullParser.END_TAG &&


xpp.getName().equalsIgnoreCase("item"))

55
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


{

insideItem=false;

eventType = xpp.next(); //move to next element

catch (MalformedURLException e)

e.printStackTrace();

catch (XmlPullParserException e)

e.printStackTrace();

catch (IOException e)

e.printStackTrace();

return null;

protected void onPostExecute(ArrayAdapter adapter)

{
56
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


adapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1,
headlines);

setListAdapter(adapter);

@Override

protected void onListItemClick(ListView l, View v, int position, long id)

Uri uri = Uri.parse((links.get(position)).toString());

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

startActivity(intent);

public InputStream getInputStream(URL url)

try

return url.openConnection().getInputStream();

catch (IOException e)

return null;

}} }

57
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


So now the Coding part is also completed.
Now run the application to see the output.

OUTPUT 

     

58
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


RESULT
Thus the program for developing an Application that makes use of RSS Feed is done using Java with
Android Studio and output is verified successfully.
Date: 08/5/21
MOBILE APPLICATION TO SEND AN E-MAIL
Ex. No: 11

AIM

To develop a mobile application to send an email procedure.

PROCEDURE

Creating a New project

 Open Android Studio and then click on File -> New -> New project.
 Then type the Application name as “ex.no.11″ and click Next.
 Then select the Minimum SDK as shown below and click Next.
 Then select the Empty Activity and click Next.
 Finally click Finish.Designing layout for the Android Application:

59
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


Designing Layout for Main Activity:

 Click on app -> res -> layout -> activity_main.xml.

 So now the designing part of Main Activity is completed.

Adding permissions in Manifest for the Android Application:

 Click on app -> manifests -> AndroidManifest.xml


AndroidManifest.xml:

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.email">

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

60
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


android:theme="@style/AppTheme">

<activity android:name=".MainActivity">

<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>

Java Coding for the Android Application

 Click on app -> java -> com.example.exno11 -> MainActivity.


PROGRAM
MainActivity.java
package com.example.email;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

61
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


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

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"));

});

62
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


}

So now the Coding part is also completed.


Now run the application to see the output.

OUTPUT

63
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

64
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

65
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

RESULT
Thus the program for developing an Application to send an E-Mail is done using Java with Android
Studio and output is verified successfully.
Date: 15/5/21 ADDITIONAL EXPERIMENTS

Ex. No: 12 NATIVE CALCULATOR APPLICATION

AIM

To develop a Simple Android Application for Native Calculator.

PROCEDURE

Creating a New project

 Open Android Studio and then click on File -> New -> New project.
 Then type the Application name as “ex.no12″ and click Next
 Then select the Minimum SDK as shown below and click Next.
 Then select the Empty Activity and click Next.
 Finally click Finish.
Designing layout for the Android Application:

Designing Layout for Main Activity:

 Click on app -> res -> layout -> activity_main.xml.

66
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 So now the designing part of Main Activity is completed.

PROGRAM

MainActivity.java

Click on app -> java -> com.example.exno12-> MainActivity.

package com.example.sam.exno;

import android.app.Activity;

import android.content.Context;

import android.os.Bundle;

import android.text.Editable;

import android.text.TextWatcher;

import android.view.KeyEvent;

import android.view.View;

import android.view.WindowManager;

67
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


import android.view.inputmethod.EditorInfo;

import android.view.inputmethod.InputMethodManager;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;

import java.util.StringTokenizer;

public class MainActivity extends Activity {

Button one,two,three,four,five,six,seven,eight,nine,zero,equal,add,sub,mul,div,c;

TextView ed;

String op1,op2,res,op,text;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

one = findViewById(R.id.one);

two = findViewById(R.id.two);

three = findViewById(R.id.three);

four = findViewById(R.id.four);

five = findViewById(R.id.five);

six = findViewById(R.id.six);

seven = findViewById(R.id.seven);

eight = findViewById(R.id.eight);

nine = findViewById(R.id.nine);

68
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


zero = findViewById(R.id.zero);

equal=findViewById(R.id.equal);

add=findViewById(R.id.plus);

sub=findViewById(R.id.sub);

mul=findViewById(R.id.mul);

div=findViewById(R.id.div);

ed = findViewById(R.id.ed);

c=findViewById(R.id.c);

one.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("1");

});

two.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("2");

});

three.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("3");

69
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


}

});

four.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("4");

});

five.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("5");

});

six.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("6");

});

seven.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("7");

70
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


}

});

eight.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("8");

});

nine.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("9");

});

zero.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("0");

});

c.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.setText("");

71
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


}

});

add.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("+");

});

sub.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("-");

});

mul.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("*");

});

div.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

ed.append("/");

72
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


}

});

equal.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

text=ed.getText().toString();

if(text.contains("+"))

StringTokenizer tokens=new StringTokenizer(text,"+");

op1=tokens.nextToken();

op2=tokens.nextToken();

op = "+";

res=String.valueOf(Integer.parseInt(op1)+Integer.parseInt(op2));

ed.setText(op1);

ed.append("+");

ed.append(op2);

ed.append("=");

ed.append(res);

if(text.contains("-"))

StringTokenizer tokens=new StringTokenizer(text,"-");

op1=tokens.nextToken();

op2=tokens.nextToken();

73
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


op = "-";

res=String.valueOf(Integer.parseInt(op1)-Integer.parseInt(op2));

ed.setText(op1);

ed.append("-");

ed.append(op2);

ed.append("=");

ed.append(res);

if(text.contains("*"))

StringTokenizer tokens=new StringTokenizer(text,"*");

op1=tokens.nextToken();

op2=tokens.nextToken();

op = "*";

res=String.valueOf(Integer.parseInt(op1)*Integer.parseInt(op2));

ed.setText(op1);

ed.append("*");

ed.append(op2);

ed.append("=");

ed.append(res);

if(text.contains("/"))

StringTokenizer tokens=new StringTokenizer(text,"/");

74
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


op1=tokens.nextToken();

op2=tokens.nextToken();

op = "/";

res=String.valueOf(Integer.parseInt(op1)/Integer.parseInt(op2));

ed.setText(op1);

ed.append("/");

ed.append(op2);

ed.append("=");

ed.append(res);

});

OUTPUT

75
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

76
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

RESULT
Thus the program for developing an Application for Calculator is done using Java with
Android Studio and output is verified successfully.

Date: 22/5/21 ADDITIONAL EXPERIMENTS

Ex. No: 13 APPLICATION THAT CREATES ALARM CLOCK

AIM

        To develop a Android Application that creates Alarm Clock.

PROCEDURE

Creating a New project

 Open Android Studio and then click on File -> New -> New project.

77
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 Then type the Application name as “ex.no13″ and click Next. 

 Then select the Minimum SDK as shown below and click Next.

78
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 Then select the Empty Activity and click Next. 

 Finally click Finish.

79
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 It will take some time to build and load the project.


 After completion it will look as given below.

Creating Second Activity for the Android Application:

 Click on File -> New -> Activity -> Empty Activity.


80
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 Type the Activity Name as AlarmReceiver and click Finish button.

 Thus Second Activity For the application is created.


Designing layout for the Android Application:

 Click on app -> res -> layout -> activity_main.xml.

81
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 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"
82
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<TimePicker

android:id="@+id/timePicker"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center" />

<ToggleButton

android:id="@+id/toggleButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:layout_margin="20dp"

android:checked="false"

android:onClick="OnToggleClicked" />

</LinearLayout>

 Now click on Design and your application will look as given below.

83
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

 So now the designing part is completed.


Changes in Manifest for the Android Application:

 Click on app -> manifests -> AndroidManifest.xml

 Now change the activity tag to receiver tag in the AndroidManifest.xml file as shown below
84
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.exno11" >

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:supportsRtl="true"

android:theme="@style/AppTheme" >

<activity android:name=".MainActivity" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

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


85
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


</intent-filter>

</activity>

<receiver android:name=".AlarmReceiver" > </receiver>

</application>

</manifest>

 So now the changes are done in the Manifest.


Java Coding for the Android Application:

Java Coding for Main Activity:

 Click on app -> java -> com.example.exno13 -> MainActivity.

 Then delete the code which is there and type the code as given below.
PROGRAM

MainActivity.java
package com.example.exno;

import android.app.AlarmManager;

import android.app.PendingIntent;

import android.content.Intent;

86
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.TimePicker;

import android.widget.Toast;

import android.widget.ToggleButton;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity

TimePicker alarmTimePicker;

PendingIntent pendingIntent;

AlarmManager alarmManager;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

alarmTimePicker = (TimePicker) findViewById(R.id.timePicker);

alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

public void OnToggleClicked(View view)

long time;

if (((ToggleButton) view).isChecked())

87
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


{

Toast.makeText(MainActivity.this, "ALARM ON", Toast.LENGTH_SHORT).show();

Calendar calendar = Calendar.getInstance();

calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getCurrentHour());

calendar.set(Calendar.MINUTE, alarmTimePicker.getCurrentMinute());

Intent intent = new Intent(this, AlarmReceiver.class);

pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

time=(calendar.getTimeInMillis()-(calendar.getTimeInMillis()%60000));

if(System.currentTimeMillis()>time)

if (calendar.AM_PM == 0)

time = time + (1000*60*60*12);

else

time = time + (1000*60*60*24);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 10000, pendingIntent);

else

alarmManager.cancel(pendingIntent);

Toast.makeText(MainActivity.this, "ALARM OFF", Toast.LENGTH_SHORT).show();

88
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


 So now the Coding part of Main Activity is completed.
Java Coding for Alarm Receiver:

 Click on app -> java -> com.example.exno13 -> AlarmReceiver.

 Then delete the code which is there and type the code as given below.

AlarmReceiver.java:
package com.example.exno13;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.media.Ringtone;

import android.media.RingtoneManager;

import android.net.Uri;

import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver

89
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********


{

@Override

public void onReceive(Context context, Intent intent)

Toast.makeText(context, "Alarm! Wake up! Wake up!", Toast.LENGTH_LONG).show();

Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);

if (alarmUri == null)

alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

Ringtone ringtone = RingtoneManager.getRingtone(context, alarmUri);

ringtone.play();

 So now the Coding part of Alarm Receiver is also completed.


 Now run the application to see the output.

90
PANIMALAR ENGINEERING COLLEGE

Department of CSE Reg no: 2114********

OUTPUT

          

RESULT
Thus the program for developing an Application that creates Alarm Clock is done using Java
with Android Studio and output is verified successfully.
91

You might also like