You are on page 1of 83

PAGE SIGNATURE

S.NO NAME OF THE EXPERIMENT


DATE NO

DEVELOP AN APPLICATION THAT


1 USES GUI COMPONENTS, FONT AND
COLOURS

DEVELOP AN APPLICATION THAT


2 USES LAYOUT MANAGERS AND
EVENT LISTENERS
WRITE AN APPLICATION THAT
3 DRAWS BASIC GRAPHICAL
PRIMITIVES ON THE SCREEN.
DEVELOP AN APPLICATION THAT
4
MAKES USE OF DATABASES

DEVELOP AN APPLICATION THAT


5 MAKES USE OF NOTIFICATION
MANAGER

IMPLEMENT AN APPLICATION THAT


6
USES MULTI-THREADING

DEVELOP A NATIVE APPLICATION


7 THAT USES GPS LOCATION
INFORMATION

IMPLEMENT AN APPLICATION THAT


8
WRITES DATA TO THE SD CARD

IMPLEMENT AN APPLICATION THAT


9 CREATES AN ALERT UPON
RECEIVING A MESSAGE

WRITE A MOBILE APPLICATION


10
THAT MAKES USE OF RSS FEED

DEVELOP A MOBILE APPLICATION


11
TO SEND AN E-MAIL

DEVELOP A MOBILE APPLICATION


12 FOR SIMPLE NEEDS (MINI PROJECT)
EX. NO: 1 DEVELOP AN APPLICATION THAT USES GUI
COMPONENTS, FONT AND COLOURS.
DATE:

AIM:

To develop an application that uses GUI components, Font and Colours..

ALGORITHM:

Step 1: Start the program.


Step 2: Open Android Studio and select New project.
Step 3: Enter application name FirstApp and select Next.
Step 4: Choose minimum SDK android version and select next.
Step 5: Select an activity Empty activity.
Step 6: Enter activity name Main Activity and Layout Name activity_main and .
Step 7: In the Project Explorer, Go to res  layout.
Step 8: Double click activity_main.xml and design the app.
Step 9: In the Project Explorer,
Go to app  java  com.example.student_pc.firstapp.
Step 10: Double click MainActivity.java and type the code.
Step 11: Run the application.
Step 12: Test the app in the Android Emulator.
Step 13: Stop the program.
Program Coding :

activity_main.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:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:gravity="center"
android:text="Hello World!"
android:textSize="25sp"
android:textStyle="bold" />

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text="Change font size"
android:textSize="25sp" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text="Change color"
android:textSize="25sp" />
</LinearLayout>
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;
@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;
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;
}
});
}
}
SAMPLE OUTPUT :
RESULT :

Thus the application for developing an GUI components , Font and colours is
successfully verified with an output.
EX. NO: 2 DEVELOP AN APPLICATION THAT USES LAYOUT
MANAGERS AND EVENT LISTENERS
DATE:

AIM:

To develop an android application that uses layout manager and event listeners.

ALGORITHM:

Step 1: Start the program.


Step 2: Open Android Studio and select New project.
Step 3: Enter application name SecondApp and select Next.
Step 4: Choose minimum SDK android version and select next.
Step 5: Select an activity Empty activity.
Step 6: Enter activity name Main Activity and Layout Name activity_main and .
Step 7: In the Project Explorer, Go to res  layout.
Step 8: Double click activity_main.xml and design the app.
Step 9: In the Project Explorer,
Go to app  java  com.example.student_pc.secondapp.
Step 10: Double click MainActivity.java and type the code.
Step 11: Run the application.
Step 12: Test the app in the Android Emulator.
Step 13: Stop the program.
Program Coding :

activity_main :

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.devang.exno2.SecondActivity"
android:orientation="vertical"
android:gravity="center">

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>

</LinearLayout>
MainActivity.java :

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 {

EditText e1,e2;
Button bt;
Spinner s;

//Data for populating in Spinner


String [] dept_array={"CSE","ECE","IT","Mech","Civil"};

String name,reg,dept;

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

//Referring the Views


e1= (EditText) findViewById(R.id.editText);
e2= (EditText) findViewById(R.id.editText2);

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

s= (Spinner) findViewById(R.id.spinner);

//Creating Adapter for Spinner for adapting the data from array to Spinner
ArrayAdapter adapter= new
ArrayAdapter(MainActivity.this,android.R.layout.simple_spinner_item,dept_arr
ay);
s.setAdapter(adapter);

//Creating Listener for Button


bt.setOnClickListener(new View.OnClickListener() {
@Override
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);

startActivity(i);

}
});
}
}
SAMPLE OUTPUT :
RESULT:

Thus the above android application to develop an layout manager and event
listeners is successfully verified with an output.
EX. NO: 3 WRITE AN APPLICATION THAT DRAWS BASIC
GRAPHICAL PRIMITIVES ON THE SCREEN
DATE:

AIM:

To write an android application that draws basic graphical primitives on the


screen.

ALGORITHM:

Step 1: Start the program.


Step 2: Open Android Studio and select New project.
Step 3: Enter application name ThirdApp and select Next.
Step 4: Choose minimum SDK android version and select next.
Step 5: Select an activity Empty activity.
Step 6: Enter activity name Main Activity and Layout Name activity_main and .
Step 7: In the Project Explorer, Go to res  layout.
Step 8: Double click activity_main.xml and design the app.
Step 9: In the Project Explorer,
Go to app  java  com.example.student_pc.thirdapp.
Step 10: Double click MainActivity.java and type the code.
Step 11: Run the application.
Step 12: Test the app in the Android Emulator.
Step 13: Stop the program.
Program Coding :

activity_main.xml :

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


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView" />
</RelativeLayout>

MainActivity.java :

package com.example.exno4;

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

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

//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);
}
}
SAMPLE OUTPUT :
RESULT:

Thus the above android application for draw a basic graphical primitives on the
screen is successfully verified with an output.
EX. NO: 4 DEVELOP AN APPLICATION THAT MAKES USE OF
DATABASES.
DATE:

AIM:
To develop an android application that makes use of the databases.

ALGORITHM :

Step 1: Start the program.


Step 2: Open Android Studio and select New project.
Step 3: Enter application name FourthApp and select Next.
Step 4: Choose minimum SDK android version and select next.
Step 5: Select an activity Empty activity.
Step 6: Enter activity name Main Activity and Layout Name activity_main and .
Step 7: In the Project Explorer, Go to res  layout.
Step 8: Double click activity_main.xml and design the app.
Step 9: In the Project Explorer,
Go to app  java  com.example.student_pc.fourthapp.
Step 10: Double click MainActivity.java and type the code.
Step 11: Run the application.
Step 12: Test the app in the Android Emulator.
Step 13: Stop the program.
Program Coding :

activity_main.xml :

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


<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="50dp"
android:layout_y="20dp"
android:text="Student Details"
android:textSize="30sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="110dp"
android:text="Enter Rollno:"
android:textSize="20sp" />

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

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

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

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

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

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

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

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

<Button
android:id="@+id/ViewAll"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_x="100dp"
android:layout_y="500dp"
android:text="View All"
android:textSize="30dp" />
</AbsoluteLayout>
MainActivity.java :

package com.example.exno5;

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,Marks;
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("StudentDB", Context.MODE_PRIVATE,
null);
db.execSQL("CREATE TABLE IF NOT EXISTS student(rollno
VARCHAR,name VARCHAR,marks VARCHAR);");
}
public void onClick(View view)
{
// Inserting a record to the Student table
if(view==Insert)
{
// Checking for empty fields
if(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();
}
// Deleting a record from the Student table
if(view==Delete)
{
// 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())
{
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)
{
// 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()) {
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;
}
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();
}
}
SAMPLE OUTPUT :
RESULT :

Thus the above android application that makes use of database is successfully
verified with an output.
EX. NO: 5 DEVELOP AN APPLICATION THAT MAKES USE OF
NOTIFICATION MANAGER
DATE:

AIM:

To develop an android application that makes use of notification manager.

ALGORITHM:

Step 1: Start the program.


Step 2: Open Android Studio and select New project.
Step 3: Enter application name FifthApp and select Next.
Step 4: Choose minimum SDK android version and select next.
Step 5: Select an activity Empty activity.
Step 6: Enter activity name Main Activity and Layout Name activity_main and .
Step 7: In the Project Explorer, Go to res  layout.
Step 8: Double click activity_main.xml and design the app.
Step 9: In the Project Explorer,
Go to app  java  com.example.student_pc.fifthapp.
Step 10: Double click MainActivity.java and type the code.
Step 11: Run the application.
Step 12: Test the app in the Android Emulator.
Step 13: Stop the program.
Program Coding :

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:layout_margin="10dp"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:textSize="30sp" />

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30sp" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:layout_gravity="center"
android:text="Notify"
android:textSize="30sp"/>

</LinearLayout>
MainActivity.java :

package com.example.exno10;

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

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_la
uncher).setContentIntent(pending).build();
NotificationManager manager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
manager.notify(0, noti);
}
});
}
}
SAMPLE OUTPUT :
RESULT:

Thus the above android application that uses the notification manager is
successfully verified with an output.
EX. NO: 6 IMPLEMENT AN APPLICATION THAT USES
MULTI-THREADING
DATE:

AIM:

To implement an android application that uses multi-threading.

ALGORITHM:

Step 1: Start the program.


Step 2: Open Android Studio and select New project.
Step 3: Enter application name SixthApp and select Next.
Step 4: Choose minimum SDK android version and select next.
Step 5: Select an activity Empty activity.
Step 6: Enter activity name Main Activity and Layout Name activity_main and .
Step 7: In the Project Explorer, Go to res  layout.
Step 8: Double click activity_main.xml and design the app.
Step 9: In the Project Explorer,
Go to app  java  com.example.student_pc.sixthapp.
Step 10: Double click MainActivity.java and type the code.
Step 11: Run the application.
Step 12: Test the app in the Android Emulator.
Step 13: Stop the program.
Program Coding :

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:orientation="vertical" >

<ImageView
android:id="@+id/imageView"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_margin="50dp"
android:layout_gravity="center" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_gravity="center"
android:text="Load Image 1" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_gravity="center"
android:text="Load image 2" />

</LinearLayout>
MainActivity.java :

package com.example.exno7;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity
{
ImageView img;
Button bt1,bt2;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

bt1 = (Button)findViewById(R.id.button);
bt2= (Button) findViewById(R.id.button2);
img = (ImageView)findViewById(R.id.imageView);

bt1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
new Thread(new Runnable()
{
@Override
public void run()
{
img.post(new Runnable()
{
@Override
public void run()
{
img.setImageResource(R.drawable.india1);
}
});
}
}).start();
}
});

bt2.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
new Thread(new Runnable()
{
@Override
public void run()
{
img.post(new Runnable()
{
@Override
public void run()
{
img.setImageResource(R.drawable.india2);
}
});
}
}).start();
}
});
}
}
SAMPLE OUTPUT :
RESULT :

Thus the above android application that develops multi-threading is


successfully verified with an output.
EX. NO: 7 DEVELOP A NATIVE APPLICATION THAT USES
DATE: GPS LOCATION INFORMATION.

AIM :

To develop a native application that uses GPS location information.

ALGORITHM :

Step 1: Start the program.


Step 2: Open Android Studio and select New project.
Step 3: Enter application name SeventhApp and select Next.
Step 4: Choose minimum SDK android version and select next.
Step 5: Select an activity Empty activity.
Step 6: Enter activity name Main Activity and Layout Name activity_main and .
Step 7: In the Project Explorer, Go to res  layout.
Step 8: Double click activity_main.xml and design the app.
Step 9: In the Project Explorer,
Go to app  java  com.example.student_pc.seventhapp.
Step 10: Double click MainActivity.java and type the code.
Step 11: Run the application.
Step 12: Test the app in the Android Emulator.
Step 13: Stop the program.
Program Coding :

activity_main.xml :

<LinearLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".MainActivityOld">

<Button
android:id="@+id/btn_start_location_updates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="@string/start_updates" />

<Button
android:id="@+id/btn_stop_location_updates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:enabled="false"
android:text="@string/stop_updates" />

<Button
android:id="@+id/btn_get_last_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/get_last_location" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:gravity="center_horizontal"
android:text="Location updates will be received only when app is
foreground" />

<TextView
android:id="@+id/location_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textColor="#333"
android:textSize="18dp" />

<TextView
android:id="@+id/updated_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:textSize="11dp" />
</LinearLayout>

MainActivity.java :

package info.androidhive.androidlocation;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.Looper;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.common.api.ResolvableApiException;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationSettingsRequest;
import com.google.android.gms.location.LocationSettingsResponse;
import com.google.android.gms.location.LocationSettingsStatusCodes;
import com.google.android.gms.location.SettingsClient;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionDeniedResponse;
import com.karumi.dexter.listener.PermissionGrantedResponse;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.single.PermissionListener;

import java.text.DateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* Reference: https://github.com/googlesamples/android-play-
location/tree/master/LocationUpdates
*/

public class MainActivity extends AppCompatActivity {

private static final String TAG = MainActivity.class.getSimpleName();

@BindView(R.id.location_result)
TextView txtLocationResult;

@BindView(R.id.updated_on)
TextView txtUpdatedOn;

@BindView(R.id.btn_start_location_updates)
Button btnStartUpdates;

@BindView(R.id.btn_stop_location_updates)
Button btnStopUpdates;

// location last updated time


private String mLastUpdateTime;

// location updates interval - 10sec


private static final long UPDATE_INTERVAL_IN_MILLISECONDS =
10000;

// fastest updates interval - 5 sec


// location updates will be received if another app is requesting the locations
// than your app can handle
private static final long
FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS = 5000;

private static final int REQUEST_CHECK_SETTINGS = 100;


// bunch of location related apis
private FusedLocationProviderClient mFusedLocationClient;
private SettingsClient mSettingsClient;
private LocationRequest mLocationRequest;
private LocationSettingsRequest mLocationSettingsRequest;
private LocationCallback mLocationCallback;
private Location mCurrentLocation;

// boolean flag to toggle the ui


private Boolean mRequestingLocationUpdates;

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

// initialize the necessary libraries


init();

// restore the values from saved instance state


restoreValuesFromBundle(savedInstanceState);
}

private void init() {


mFusedLocationClient =
LocationServices.getFusedLocationProviderClient(this);
mSettingsClient = LocationServices.getSettingsClient(this);

mLocationCallback = new LocationCallback() {


@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
// location is received
mCurrentLocation = locationResult.getLastLocation();
mLastUpdateTime = DateFormat.getTimeInstance().format(new
Date());

updateLocationUI();
}
};

mRequestingLocationUpdates = false;

mLocationRequest = new LocationRequest();

mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);

mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_
MILLISECONDS);

mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURA
CY);

LocationSettingsRequest.Builder builder = new


LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
mLocationSettingsRequest = builder.build();
}

/**
* Restoring values from saved instance state
*/
private void restoreValuesFromBundle(Bundle savedInstanceState) {
if (savedInstanceState != null) {
if (savedInstanceState.containsKey("is_requesting_updates")) {
mRequestingLocationUpdates =
savedInstanceState.getBoolean("is_requesting_updates");
}

if (savedInstanceState.containsKey("last_known_location")) {
mCurrentLocation =
savedInstanceState.getParcelable("last_known_location");
}

if (savedInstanceState.containsKey("last_updated_on")) {
mLastUpdateTime =
savedInstanceState.getString("last_updated_on");
}
}

updateLocationUI();
}

/**
* Update the UI displaying the location data
* and toggling the buttons
*/
private void updateLocationUI() {
if (mCurrentLocation != null) {
txtLocationResult.setText(
"Lat: " + mCurrentLocation.getLatitude() + ", " +
"Lng: " + mCurrentLocation.getLongitude()
);

// giving a blink animation on TextView


txtLocationResult.setAlpha(0);
txtLocationResult.animate().alpha(1).setDuration(300);

// location last updated time


txtUpdatedOn.setText("Last updated on: " + mLastUpdateTime);
}

toggleButtons();
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean("is_requesting_updates",
mRequestingLocationUpdates);
outState.putParcelable("last_known_location", mCurrentLocation);
outState.putString("last_updated_on", mLastUpdateTime);

private void toggleButtons() {


if (mRequestingLocationUpdates) {
btnStartUpdates.setEnabled(false);
btnStopUpdates.setEnabled(true);
} else {
btnStartUpdates.setEnabled(true);
btnStopUpdates.setEnabled(false);
}
}

/**
* Starting location updates
* Check whether location settings are satisfied and then
* location updates will be requested
*/
private void startLocationUpdates() {
mSettingsClient
.checkLocationSettings(mLocationSettingsRequest)
.addOnSuccessListener(this, new
OnSuccessListener<LocationSettingsResponse>() {
@SuppressLint("MissingPermission")
@Override
public void onSuccess(LocationSettingsResponse
locationSettingsResponse) {
Log.i(TAG, "All location settings are satisfied.");

Toast.makeText(getApplicationContext(), "Started location


updates!", Toast.LENGTH_SHORT).show();
//noinspection MissingPermission

mFusedLocationClient.requestLocationUpdates(mLocationRequest,
mLocationCallback, Looper.myLooper());

updateLocationUI();
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
int statusCode = ((ApiException) e).getStatusCode();
switch (statusCode) {
case
LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
Log.i(TAG, "Location settings are not satisfied. Attempting
to upgrade " +
"location settings ");
try {
// Show the dialog by calling startResolutionForResult(),
and check the
// result in onActivityResult().
ResolvableApiException rae = (ResolvableApiException)
e;
rae.startResolutionForResult(MainActivity.this,
REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException sie) {
Log.i(TAG, "PendingIntent unable to execute request.");
}
break;
case
LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
String errorMessage = "Location settings are inadequate,
and cannot be " +
"fixed here. Fix in Settings.";
Log.e(TAG, errorMessage);
Toast.makeText(MainActivity.this, errorMessage,
Toast.LENGTH_LONG).show();
}

updateLocationUI();
}
});
}

@OnClick(R.id.btn_start_location_updates)
public void startLocationButtonClick() {
// Requesting ACCESS_FINE_LOCATION using Dexter library
Dexter.withActivity(this)
.withPermission(Manifest.permission.ACCESS_FINE_LOCATION)
.withListener(new PermissionListener() {
@Override
public void onPermissionGranted(PermissionGrantedResponse
response) {
mRequestingLocationUpdates = true;
startLocationUpdates();
}

@Override
public void onPermissionDenied(PermissionDeniedResponse
response) {
if (response.isPermanentlyDenied()) {
// open device settings when the permission is
// denied permanently
openSettings();
}
}

@Override
public void
onPermissionRationaleShouldBeShown(PermissionRequest permission,
PermissionToken token) {
token.continuePermissionRequest();
}
}).check();
}

@OnClick(R.id.btn_stop_location_updates)
public void stopLocationButtonClick() {
mRequestingLocationUpdates = false;
stopLocationUpdates();
}

public void stopLocationUpdates() {


// Removing location updates
mFusedLocationClient
.removeLocationUpdates(mLocationCallback)
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(getApplicationContext(), "Location updates
stopped!", Toast.LENGTH_SHORT).show();
toggleButtons();
}
});
}

@OnClick(R.id.btn_get_last_location)
public void showLastKnownLocation() {
if (mCurrentLocation != null) {
Toast.makeText(getApplicationContext(), "Lat: " +
mCurrentLocation.getLatitude()
+ ", Lng: " + mCurrentLocation.getLongitude(),
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Last known location is not
available!", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch (requestCode) {
// Check for the integer request code originally supplied to
startResolutionForResult().
case REQUEST_CHECK_SETTINGS:
switch (resultCode) {
case Activity.RESULT_OK:
Log.e(TAG, "User agreed to make required location settings
changes.");
// Nothing to do. startLocationupdates() gets called in onResume
again.
break;
case Activity.RESULT_CANCELED:
Log.e(TAG, "User chose not to make required location settings
changes.");
mRequestingLocationUpdates = false;
break;
}
break;
}
}

private void openSettings() {


Intent intent = new Intent();
intent.setAction(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package",
BuildConfig.APPLICATION_ID, null);
intent.setData(uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}

@Override
public void onResume() {
super.onResume();

// Resuming location updates depending on button state and


// allowed permissions
if (mRequestingLocationUpdates && checkPermissions()) {
startLocationUpdates();
}

updateLocationUI();
}

private boolean checkPermissions() {


int permissionState = ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION);
return permissionState == PackageManager.PERMISSION_GRANTED;
}

@Override
protected void onPause() {
super.onPause();

if (mRequestingLocationUpdates) {
// pausing location updates
stopLocationUpdates();
}
}
}
SAMPLE OUTPUT :
RESULT :

Thus the above android application that uses GPS location information is
successfully verified with an output.
EX. NO: 8 IMPLEMENT AN APPLICATION THAT WRITES DATA
TO THE SD CARD.
DATE:

AIM:

To implement an android application that writes data to the SD card.

ALGORITHM:

Step 1: Start the program.


Step 2: Open Android Studio and select New project.
Step 3: Enter application name EigthApp and select Next.
Step 4: Choose minimum SDK android version and select next.
Step 5: Select an activity Empty activity.
Step 6: Enter activity name Main Activity and Layout Name activity_main and .
Step 7: In the Project Explorer, Go to res  layout.
Step 8: Double click activity_main.xml and design the app.
Step 9: In the Project Explorer,
Go to app  java  com.example.student_pc.eightapp.
Step 10: Double click MainActivity.java and type the code.
Step 11: Run the application.
Step 12: Test the app in the Android Emulator.
Step 13: Stop the program.
Program Coding :

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:layout_margin="20dp"
android:orientation="vertical">

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30dp" />

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Write Data"
android:textSize="30dp" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Read data"
android:textSize="30dp" />

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Clear"
android:textSize="30dp" />

</LinearLayout>

MainActivity.java :

package com.example.exno9;

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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;

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)
{
String message=e1.getText().toString();
try
{
File f=new File("/sdcard/myfile.txt");
f.createNewFile();
FileOutputStream fout=new FileOutputStream(f);
fout.write(message.getBytes());
fout.close();
Toast.makeText(getBaseContext(),"Data Written in
SDCARD",Toast.LENGTH_LONG).show();
}
catch (Exception e)
{

Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).sho
w();
}
}
});

read.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String message;
String buf = "";
try
{
File f = new File("/sdcard/myfile.txt");
FileInputStream fin = new FileInputStream(f);
BufferedReader br = new BufferedReader(new
InputStreamReader(fin));
while ((message = br.readLine()) != null)
{
buf += message;
}
e1.setText(buf);
br.close();
fin.close();
Toast.makeText(getBaseContext(),"Data Recived from
SDCARD",Toast.LENGTH_LONG).show();
}
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("");
}
});
}
}
SAMPLE OUTPUT :
RESULT :

Thus the above android application that writes data to the SD card is
successfully verified with an output.
EX. NO: 9 IMPLEMENT AN APPLICATION THAT CREATES AN
ALERT UPON RECEIVING A MESSAGE
DATE:

AIM :

To implement an android application that creates an alert upon receiving a


message.

ALGORITHM :

Step 1: Start the program.


Step 2: Open Android Studio and select New project.
Step 3: Enter application name NinthApp and select Next.
Step 4: Choose minimum SDK android version and select next.
Step 5: Select an activity Empty activity.
Step 6: Enter activity name Main Activity and Layout Name activity_main and .
Step 7: In the Project Explorer, Go to res  layout.
Step 8: Double click activity_main.xml and design the app.
Step 9: In the Project Explorer,
Go to app  java  com.example.student_pc.ninthapp.
Step 10: Double click MainActivity.java and type the code.
Step 11: Run the application.
Step 12: Test the app in the Android Emulator.
Step 13: Stop the program.
Program Coding :

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:layout_margin="10dp"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:textSize="30sp" />

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30sp" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:layout_gravity="center"
android:text="Notify"
android:textSize="30sp"/>

</LinearLayout>
MainActivity.java :

package com.example.exno10;

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

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_la
uncher).setContentIntent(pending).build();
NotificationManager manager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
manager.notify(0, noti);
}
});
}
}
SAMPLE OUTPUT :
RESULT :

Thus the above android application that creates an alert upon receiving a
message is successfully verified with an output.
EX. NO: 10 WRITE A MOBILE APPLICATION THAT MAKES USE OF
RSS FEED.
DATE:

AIM :

To develop an android application that makes use of RSS feed.

ALGORITHM :

Step 1: Start the program.


Step 2: Open Android Studio and select New project.
Step 3: Enter application name TenthApp and select Next.
Step 4: Choose minimum SDK android version and select next.
Step 5: Select an activity Empty activity.
Step 6: Enter activity name Main Activity and Layout Name activity_main and .
Step 7: In the Project Explorer, Go to res  layout.
Step 8: Double click activity_main.xml and design the app.
Step 9: In the Project Explorer,
Go to app  java  com.example.student_pc.tenthapp.
Step 10: Double click MainActivity.java and type the code.
Step 11: Run the application.
Step 12: Test the app in the Android Emulator.
Step 13: Stop the program.
Program Coding :

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

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

</LinearLayout>

MainActivity.java:

package com.example.exno6;

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


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"))
{
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)
{
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;
}
}
}
SAMPLE OUTPUT :
RESULT :

Thus the above android application that makes use of RSS feed is successfully
verified with an output.
EX. NO: 11 DEVELOP AN MOBILE APPLICATION THAT
DATE: SEND AN E-MAIL

AIM :

To develop an android application that sends an e-mail

ALGORITHM :

Step 1: Start the program.


Step 2: Open Android Studio and select New project.
Step 3: Enter application name EleventhApp and select Next.
Step 4: Choose minimum SDK android version and select next.
Step 5: Select an activity Empty activity.
Step 6: Enter activity name Main Activity and Layout Name activity_main and .
Step 7: In the Project Explorer, Go to res  layout.
Step 8: Double click activity_main.xml and design the app.
Step 9: In the Project Explorer,
Go to app  java  com.example.student_pc.eleventhapp.
Step 10: Double click MainActivity.java and type the code.
Step 11: Run the application.
Step 12: Test the app in the Android Emulator.
Step 13: Stop the program.
Program Coding :

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>
MainActivity.java :

package com.tutlane.sendmailexample;
import android.content.Intent;
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 {

private EditText eTo;


private EditText eSubject;
private EditText eMsg;
private Button btn;
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"));
}
});
}
}
SAMPLE OUTPUT :
RESULT :

Thus the above android application that send an e-mail is successfully verified
with an output.

You might also like