Professional Documents
Culture Documents
Tharun Kumar L Madlab Record
Tharun Kumar L Madlab Record
ENGINEERING COLLEGE
PONMAR,CHENNAI-600127
REGISTER NO : 411719104053
Register No : 411719104053
Semester : 06
Certified that this is a Bonafide Record of practical work done by the above
year 2021-2022.
Notification Manager
information
Card
receiving a message
Feed
(Mini Project)
411719104053
Aim
To develop an application that uses GUI components, Font and Colors.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
Step 5: Use F2 key to edit the name of the tools
Step 6: Use Ctrl + tab in the activitymain.xml file to view the hints without typing fully
Step 7: Open MainActivity.java file and type the code inside the class
Step 8: Steps to create a emulator
8 (a): Got to menu Window → Android Virtual Device Manager
8(b): Select New → Type AVD name and click OK
Step 9: Stop the program
1
411719104053
2
411719104053
PROGRAM CODING
//GUI COMPONENTS-FONTS AND COLORS
MainActivity.java
package com.example.admin.actionandevent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
float font=24;int i=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t1=(TextView)findViewById(R.id.textView);
Button b1=(Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
t1.setTextSize(font);
font = font + 4;
3
411719104053
if (font == 40) {
font = 20;
} }
});
Button b2=(Button)findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v)
{
Switch(i)
{
case 1:t1.setTextColor(Color.parseColor("#00ff00"));
i++;
break;
case 2:t1.setTextColor(Color.parseColor("#ff0000"));
i++;
break;
case 3:t1.setTextColor(Color.parseColor("#0000ff"));
i++;
break;
case 4:t1.setTextColor(Color.parseColor("#00f0f0"));
i++;
break;
default:break;
}
if(i==5)
i=1;
}
});
}
}
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.admin.actionandevent.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
4
411719104053
5
411719104053
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="change font size"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="112dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="change text color"
android:id="@+id/button2"
android:layout_marginTop="240dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/button"
android:layout_alignStart="@+id/button" />
</RelativeLayout>
6
411719104053
OUTPUT
RESULT
Thus the mobile application that uses GUI components, Font and Colors has been developed
successfully.
7
411719104053
Aim
To develop an application that uses Layout Managers and event listeners
Algorithm
8
411719104053
PROGRAM CODING
//LAYOUT MANAGERS AND EVENT LISTENERS
MainActivity.java
package com.example.admin.guifont10;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button btn;
RelativeLayout canvas;
EditText edtuser,edtpass;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=(Button)findViewById(R.id.button);
edtuser=(EditText)findViewById(R.id.edtusername);
edtpass=(EditText)findViewById(R.id.edtpassword);
canvas=(RelativeLayout)findViewById(R.id.canvas);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username=null,password=null;
username=edtuser.getText().toString();
password=edtpass.getText().toString();
if(username.equals("prince")&&password.equals("1234"))
{
Toast.makeText(getApplicationContext(),"user
authenticated",Toast.LENGTH_LONG).show();
canvas.setBackgroundResource(R.color.colorAccent);
}
else
Toast.makeText(getApplicationContext(),"check your
credentials",Toast.LENGTH_LONG).show();
}
});
}
}
9
411719104053
Activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:id="@+id/edtpwd"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edtusername"
android:layout_alignTop="@+id/edtuser"
android:layout_alignRight="@+id/imageView"
android:layout_alignEnd="@+id/imageView"
android:layout_marginRight="96dp"
10
411719104053
android:layout_marginEnd="96dp"
android:layout_toRightOf="@+id/edtuser"
android:layout_toEndOf="@+id/edtuser" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/edtpassword"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username is "prince" and password is"1234""
android:id="@+id/textView"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="81dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="change bg color"
android:id="@+id/button"
android:layout_above="@+id/textView"
android:layout_centerHorizontal="true" />
</RelativeLayout>
11
411719104053
OUTPUT
RESULT
Thus a Simple Android Application that uses Layout Managers and Event Listeners is
developed and executed successfully.
12
411719104053
Aim
To develop an application that draws basic graphical primitives on the screen.
Algorithm
6(e):drawLine() method is used to draw the Line onn the Screen at the specified pixel
position and filled with specified paint color
Step 7: Steps to create a emulator
7 (a): Got to menu Window → Android Virtual Device Manager
7(b): Select New → Type AVD name and click OK
Step 8: Stop the program
13
411719104053
PROGRAM CODING
//BASIC GRAPHICAL PRIMITIVES
MainActivity.java
package com.example.admin.basicgraphicalprimitivesapp;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new myView(this));
}
private class myView extends View
{
public myView(Context context)
{
super(context);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
Paint paint=new Paint();
paint.setTextSize(40);
paint.setColor(Color.GREEN);
canvas.drawText("Circle", 55, 30, paint);
paint.setColor(Color.RED);
canvas.drawCircle(100, 150, 100, paint);
paint.setColor(Color.GREEN);
canvas.drawText("Rectangle", 255, 30, paint);
paint.setColor(Color.YELLOW);
canvas.drawRect(250, 50, 400, 350, paint);
paint.setColor(Color.GREEN);
canvas.drawText("Square", 55, 430, paint);
paint.setColor(Color.BLUE);
canvas.drawRect(50, 450, 150, 550, paint);
paint.setColor(Color.GREEN);
canvas.drawText("Line", 255, 430, paint);
paint.setColor(Color.GREEN);
canvas.drawLine(250, 550,350 , 550, paint);
}
}
14
411719104053
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.admin.basicgraphicalprimitivesapp.MainActivity"
android:id="@+id/canvas">
</RelativeLayout>
15
411719104053
OUTPUT
RESULT
Thus, the mobile application that draws basic graphical primitives on the screen has been developed
successfully
16
411719104053
Aim
To develop an application that makes use of database.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
4(a): insert five buttons for various operations on the database such as
Add,Modify,Delete,View and view_all
4(b):insert three plaintext field one for Employee id,Employee name and Employee Salary.
6(e):define the code for Modify button to get the Employee id,employee name and employee
salary and modify the record in the database using SQL UPDATE command.
6(f):define the code for view_all button to execute SOL SELECT command to display all the
records from the database.
6(g): define the code for view button to get the employee id and display the particular record
from the database using SQL SELECT command .
17
411719104053
PROGRAM CODING
//CREATE DATABASE USING ANDROID APPLICATION
MainActivity.java
package com.example.admin.empdetails;
import android.app.AlertDialog;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
}
clearText();
}
if(view==btnView)
{
if(editEmpid.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Employee id");
return;
}
Cursor c=db.rawQuery("SELECT * FROM employee WHERE
empid='"+editEmpid.getText()+"'", null);
if(c.moveToFirst())
{
editName.setText(c.getString(1));
editsalary.setText(c.getString(2));
}
else
{
showMessage("Error", "Invalid Employee id");
clearText();
}
}
if(view==btnViewAll)
{
Cursor c=db.rawQuery("SELECT * FROM employee", null);
if(c.getCount()==0)
{
showMessage("Error", "No records found");
return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("Employee id: "+c.getString(0)+"\n");
buffer.append("Name: "+c.getString(1)+"\n");
buffer.append("salary: "+c.getString(2)+"\n\n");
}
showMessage("Employee Details", buffer.toString());
}
}
public void showMessage(String title,String message)
{
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
20
411719104053
}
public void clearText()
{
editEmpid.setText("");
editName.setText("");
editsalary.setText("");
editEmpid.requestFocus();
}
}
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:stretchColumns="0"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="EMPLOYEE DATABASE MANAGEMENT APPLICATION"
android:layout_x="18dp"
android:layout_y="9dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:text="empid"
android:layout_x="30dp"
android:layout_y="50dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText android:id="@+id/editEmpid"
android:inputType="number"
android:layout_x="150dp"
android:layout_y="50dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
<TextView android:text="name"
android:layout_x="30dp"
android:layout_y="100dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText android:id="@+id/editName"
android:inputType="text"
android:layout_x="150dp"
android:layout_y="100dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
<TextView android:text="salary"
android:layout_x="30dp"
android:layout_y="150dp"
android:layout_width="wrap_content"
21
411719104053
android:layout_height="wrap_content"/>
<EditText android:id="@+id/editsalary"
android:inputType="number"
android:layout_x="150dp"
android:layout_y="150dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnAdd"
android:text="add"
android:layout_x="30dp"
android:layout_y="200dp"
android:layout_width="130dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnDelete"
android:text="delete"
android:layout_x="160dp"
android:layout_y="200dp"
android:layout_width="130dp"
android:layout_height="40dp"/>n
<Button android:id="@+id/btnModify"
android:text="modify"
android:layout_x="30dp"
android:layout_y="250dp"
android:layout_width="130dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnView"
android:text="view"
android:layout_x="160dp"
android:layout_y="250dp"
android:layout_width="130dp"
android:layout_height="40dp"/>
<Button android:id="@+id/btnViewAll"
android:text="view_all"
android:layout_x="85dp"
android:layout_y="300dp"
android:layout_width="150dp"
android:layout_height="40dp"/>
</AbsoluteLayout>
22
411719104053
OUTPUT
1. Add a record into the database
23
411719104053
4. View all
RESULT
Thus the android application that uses the database has been developed successfully
24
411719104053
Aim
To develop an mobile application that creates an alarm clock.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
4(a):A button that is used to set the target time.
4(b):A text box to display the Alarm time that is set
Step 5: Open MainActivity.java file and type the code inside the class to do the following
5(a):Create a time picker dialog object using the TimePickerDialog class when the button to set
the alarm is clicked the onclick() method is invoked to display the time in hours and minutes using
the opentimepickerDialog()method.
5(b):In the openTimePickerDialog() method use the calendar class and the timepickerDialog
class objects to create a time picker window with the title Set AlarmTime
5(c):OnTimeSet() method is used to set the alarm time and compare the Alarm set time with
the current time.if it becomes true then setAlarm() method is invoked.
5(d):setAlarm() method is used to display the Alarm set time on the mobile screen in the text
area.
5(e):Using the objects of Intentclass and the alarm manager class it gets the system services and
an intent to the AlarmReceiver class.
Step 6: create a AlarmReceiver .java file in the src directory and in that class define the onReceiver()
method to display the toast message that the alarm has been received.
Step 7:in the AndroidManifest.xml file use the receiver xml tag with android:name attribute and
android:process attribute to connect with the remote AlarmReceiver class.
Step 8: Launch the application using the emulator.
Step 9: Stop the program.
25
411719104053
CODING
//ALARM
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="admin.example.com.alarm">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".AlarmReceiver" android:process=":remote"/>
</application>
</manifest>
Main_Activity.java
package admin.example.com.alarm;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
26
411719104053
import java.util.Calendar;
calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
calSet.set(Calendar.MINUTE, minute);
27
411719104053
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);
if(calSet.compareTo(calNow) <= 0){
//Today Set time passed, count to tomorrow
calSet.add(Calendar.DATE, 1);
}
setAlarm(calSet);
}};
private void setAlarm(Calendar targetCal){
textAlarmPrompt.setText(
"\n\n***\n"
+ "Alarm is set@ " + targetCal.getTime() + "\n"
+ "***\n");
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1,
intent, 0);
AlarmManager alarmManager =
(AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(),
pendingIntent);
}
}
AlarmReceiver.java
package admin.example.com.alarm;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
}
}
28
411719104053
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/Title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical|center_horizontal"
android:text="ALARM CLOCK"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/startSetDialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set Target Time"/>
<TextView
android:id="@+id/alarmprompt"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout/>
29
411719104053
OUTPUT:
30
411719104053
RESULT
Thus, the mobile application that creates an alarm clock has been developed successfully.
31
411719104053
EX NO :6 MULTITHREADING
Aim
To develop an application to implement multithreading concept.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project.
Step 3: Output wizard in layout → activitymain.xml → graphical layout.
Step 4: Design the required tool in the palette window.
Step 5: Use F2 key to edit the name of the tools
Step 6: Open MainActivity.java file and type the code inside the class.
Step 7: Create a button named Start Multithreading and set onclick event as fetchData()
method in Activity_main.xml.
Step 8: Define fetchData() method to perform multithreading.
Step 9: Use Thread class for creating the thread.
9(a): set start() method to initialize the thread.
9(b): set run() method for each thread to execute the thread.
9(c): set sleep() method to make the thread to enter into the waiting state.
Step 10: create Handler class for handling thread messages.
Step 11: Steps to create a emulator
11 (a): Go to menu Window → Android Virtual Device Manager
11(b): Select New → Type AVD name and click OK
Step 12: Stop the program
32
411719104053
PROGRAM CODING:
//MULTITHREADING
Main_Activity.java
package admin.example.com.multithread;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
handler.sendEmptyMessage(t1);
}
}
});
Thread thread2=new Thread(new Runnable() {
@Override
public void run() {
for(int i=0;i<5;i++)
{
try{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
handler.sendEmptyMessage(t2);
}
}
});
Thread thread3=new Thread(new Runnable() {
@Override
public void run() {
for(int i=0;i<5;i++)
{
try{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
handler.sendEmptyMessage(t1);
}
}
});
Handler handler=new Handler()
{
public void handleMessage(android.os.Message msg)
{
if(msg.what==t1)
{
tvoutput.append("\n in thread 1");
}
if(msg.what==t2)
{
tvoutput.append("\n in thread 2");
}
if(msg.what==t3)
{
34
411719104053
Activity_main.xml:
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/info" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="fetchData"
android:text="Start MULTITHREAD" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Main thread" />
</LinearLayout>
35
411719104053
OUTPUT:
RESULT
Thus the android application to implement Multithreading concept has been developed
successfully.
36
411719104053
Aim
To develop an native application that uses GPS location information
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
4(a):A button that is used to show the location
Step 5: Open MainActivity.java file and type the code inside the class to do the following
5(a):when the show location button is clicked create an object for the GPStrace class
and using that object check whether we can get the location using cangetLocation() method.
5(b): if true,show the latitude and the longitude using toast message
Step 6: create a GPStrace.java file in the srcdirectory and write the code
6(a):getlocation() method is used to get the location using the LocationManeger object.
6(b):isGPSEnabled field is used to check whether the GPS service is enabled or not.
6(c):isNetworkEnabled field is used to check whether the network is enabled or not.
6(d):if the isNetworkEnabled is true then return the location by checking the manifest
fie permission.
6(e):in the showSettingalert() method specify whether all the services and permissions
required to retrieve the GPS location are enabeled or not
Step 7:in the AndroidManifest.xml file use the uses-permission xml tag to give the internet
permission.
Step 8: Launch the application using the emulator then go to tools->android->android device
manager->emulator control. Send the loction information to the emulator.
Step 9: Stop the program.
37
411719104053
PROGRAM CODING:
//GPS
AndroidMenifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.gpspri" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Main_Activity.java
package com.example.admin.gps;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnShowLocation=(Button)findViewById(R.id.show_Location);
btnShowLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
gps=new GPStrace(MainActivity.this);
if(gps.canGetLocation()){
double latitude=gps.getLatitude();
double longitude=gps.getLongtiude();
Toast.makeText(getApplicationContext(),"Your Location is
\nLat:"+latitude+"\nLong:"+longitude, Toast.LENGTH_LONG).show();
}
else
{
gps.showSettingAlert();
}
}
});
}
}
GPStrace.java:
package com.example.admin.gpspri;
import android.Manifest;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
39
411719104053
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
40
411719104053
}
if (locationManager != null) {
location =
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location =
locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
41
411719104053
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
alertDialog.show();
}
@Override
public void onLocationChanged(Location location) {
42
411719104053
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/show_Location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show_Location"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
43
411719104053
OUTPUT:
44
411719104053
RESULT
Thus, the mobile application that uses GPS location information has been developed
successfully.
45
411719104053
EX NO:8 SD-CARD
Aim
To Implement an application that writes data to the SD card.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
4(a): Two buttons are placed one is used for saving the data into the sdcard and other
is to load the data from sdcard
4(b): A textfield is used to write the data which is t be saved in the sdcard
Step 5: Open MainActivity.java file and type the code inside the class to do the following
5(a): get the message from the edittext component once the save button is clicked.
5(b): invoke the getExternalStorageDirectory() method using the Environment class
5(c): Create a fileDirectory in the sdcard called “mydirectory” using the mkdirs()
method.
5(d): Write the message into a text file using the file outpustreams and save it in the
directory.
5(e): when the load button is clicked get the message from the file which is placed in
mydirectory of the external sdcard and display it to the user using the toast message
Step 6 : In the AndroidManifest.xml file use the uses-permission xml tag to give the Write
_external storage permission
Step 7: Launch the application using the emulator.
Step 8: Stop the program
46
411719104053
PROGRAM CODING:
//SDCARD STORAGE
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.sdcard_harsh"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application
android:icon="@mipmap/ic_launcher"
android:label="SDCARD" >
<activity
android:name=".MainActivity"
android:label="SDCARD" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</menifest>
Main_Activity.java
package com.example.admin.sdcard;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
package com.example.admin.sdcard;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
47
411719104053
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
48
411719104053
}catch(IOException e){
e.printStackTrace();
}
}catch (FileNotFoundException e){
e.printStackTrace();
}
}
});
load.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
try{
File sdcard=Environment.getExternalStorageDirectory();
File directory=new File(sdcard.getAbsolutePath()+"/MyDirectory");
File file=new File(directory,"textfile.txt");
FileInputStream fis=new FileInputStream(file);
InputStreamReader isr=new InputStreamReader(fis);
char[] data=new char[100];
String final_data="";
int size;
try{
while((size=isr.read(data))>0)
{
//read a data from file
String read_data=String.copyValueOf(data,0,size);
final_data+=read_data;
data=new char[100];
}
//display the data in output
Toast.makeText(getBaseContext(),"Message:"+final_data,Toast.LENGTH_LONG).show();
}catch(IOException e){
e.printStackTrace();
}
}catch (FileNotFoundException e){
e.printStackTrace();
}
}
49
411719104053
});
}
Activity_main.xml:
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SAVE DATA" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SHOW DATA" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
50
411719104053
OUTPUT:
51
411719104053
52
411719104053
RESULT
Thus the android application for writing data into the SD-card Storage has been developed
successfully.
53
411719104053
Aim
To develop an application that creates alert upon receiving a message.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
Step 5: Use F2 key to edit the name of the tools
Step 6: Use Ctrl + tab in the activitymain.xml file to view the hints without typing fully
Step 7: Open MainActivity.java file and type the code inside the class
Step 8 :CreateRadioGroup for each question and set OnCheckedChangeListener() for
each RadioGroup.
Step9: define code for OnCheckedChanged() to get the answer.
9(a): define switch case to assign the score to the selected answer for each
RadioGroup.
Step 10: create a button named Submit and set OnClickListener() to that button.
Step 11: Create AlertDialogBuilder class for showing alerts.
11(a): set alert title as SHOW RESULT and alert message.
11(b): define code for setPositiveButton and setOnClickListener() to that button.
11(c): define code for setNegetiveButton and setOnClickListener() to that button.
Step 12: Steps to create a emulator
12(a): Got to menu Window → Android Virtual Device Manager
12(b): Select New → Type AVD name and click OK
Step 13: Stop the program
54
411719104053
PROGRAM CODING:
//ALERT
Main_Activity.java
package admin.example.com.alert;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.Toast;
break;
}
}
});
RadioGroup b2=(RadioGroup)findViewById(R.id.answer2);
b2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch(checkedId) {
case R.id.answer2A:
ans2=1;
break;
case R.id.answer2B:
ans2=2;
break;
case R.id.answer2C:
ans2=3;
break;
case R.id.answer2D:
ans2=4;
break;
}
}
});
RadioGroup b3=(RadioGroup)findViewById(R.id.answer3);
b3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.answer3A:
ans3 =1;
break;
case R.id.answer3B:
ans3 =2;
break;
case R.id.answer3C:
ans3 =3;
break;
case R.id.answer3D:
ans3 =4;
break;
}
}
});
RadioGroup b4=(RadioGroup)findViewById(R.id.answer4);
56
411719104053
b4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.answer4A:
ans4 =1;
break;
case R.id.answer4B:
ans4 =2;
break;
case R.id.answer4C:
ans4=3;
break;
case R.id.answer4D:
ans4 =4;
break;
}
}
});
score =0;
// TODO Auto-generated method stub
if(ans1 == 2)
score++;
if(ans2 == 3)
score++;
if(ans3 == 1)
score++;
57
411719104053
if(ans4 == 4)
58
411719104053
score++;
Toast.makeText(MainActivity.this, "Your score is:" + score + " out of 4.",
Toast.LENGTH_LONG).show();
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke NO event
Toast.makeText(getApplicationContext(), "You clicked NO.CHECK YOUR
ANSWER", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
alertDialog.show(); // Showing Alert Message
}
});
}
}
Activity_main.xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:background="#f2baf2">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*”
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="@+id/Title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical|center_horizontal"
android:text="QUIZ"
android:textSize="25sp"
59
411719104053
android:textStyle="bold" />
<View
android:layout_height="2px"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:background="#DDFFDD"/>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18sp" android:text="1.GSM is" android:layout_span="4"
android:padding="18dip"android:textColor="#121111"/></TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<RadioGroup
android:id="@+id/answer1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4" >
<RadioButton
android:id="@+id/answer1A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#110f0f"
android:text="global science management"
android:checked="false" />
<RadioButton
android:id="@+id/answer1B"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="global system for mobile computing"
android:checked="false" />
<RadioButton
android:id="@+id/answer1C"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Great science master"
android:checked="false" />
60
411719104053
<RadioButton
android:id="@+id/answer1D"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="Global system management"
android:checked="false" />
</RadioGroup>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18sp"
android:text="2.Which is NOT the characteristics of Mobile computing"
android:layout_span="4"
android:padding="18dip"
android:textColor="#161416"/></TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<RadioGroup
android:id="@+id/answer2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4" >
<RadioButton
android:id="@+id/answer2A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="broadcast"
android:checked="false" />
<RadioButton
android:id="@+id/answer2B"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="ubiquity"
android:checked="false" />
<RadioButton
61
411719104053
android:id="@+id/answer2C"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="interoperability"
android:checked="false" />
<RadioButton
android:id="@+id/answer2D"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="location awareness"
android:checked="false" />
</RadioGroup>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18sp"
android:text="3.BUS is a" android:layout_span="4"
android:padding="18dip"
android:textColor="#000000"/></TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<RadioGroup
android:id="@+id/answer3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4" >
<RadioButton
android:id="@+id/answer3A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="peer to peer architechture"
android:checked="false" />
<RadioButton
android:id="@+id/answer3B"
android:layout_width="match_parent"
android:layout_height="wrap_content"
62
411719104053
android:textColor="#000000"
android:text="packet forwarding"
android:checked="false" />
<RadioButton
android:id="@+id/answer3C"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="topology which follows round robin "
android:checked="false" />
<RadioButton
android:id="@+id/answer3D"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="none of the above"
android:checked="false" />
</RadioGroup></TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18sp"
android:text="4.which is not a category in fixed assignment scheme"
android:layout_span="4"
android:padding="18dip"
android:textColor="#000000"/></TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<RadioGroup
android:id="@+id/answer4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4" >
<RadioButton
android:id="@+id/answer4A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="FDMA"
android:checked="false" />
63
411719104053
<RadioButton
android:id="@+id/answer4B"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="TDMA"
android:checked="false" />
<RadioButton
android:id="@+id/answer4C"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="CDMA"
android:checked="false" />
<RadioButton
android:id="@+id/answer4D"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="CSMA"
android:checked="false" />
</RadioGroup></TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Submit /></TableRow>
</TableLayout>
</ScrollView>
64
411719104053
OUTPUT:
65
411719104053
RESULT
Thus, the android application that creates alert upon receiving a message has been developed
successfully.
66
411719104053
Aim
To develop an application that makes use of RSS feed
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Design the required tool in the palette window
3(a):In the activity_main.xml file use the list view to display the courses available
3(b): in rss_list_layout.xml file use the textview components to view the title and the links.
3(c): in main_list_layout.xml file use the textvies for the index and the titles.
3(d):in activity_rss_loader.xml file use the Listview and the process bars
Step 4: create the following java files and write the code in it
4(a):in MainActivity.java create an arrayList for the courses and the rss-path .add the courses
to the ListView and use the MainListAdapter object to handle the events of the listView with the
arguments as the rss_list_layout and the course class.
4(b): Rssloader.java write the code to load the feed from the links to display it in the screen
using the processbar of theActivity_rss_loader
4(c): MainListAdapter.java get the index and the titles and display it on to the screen using
the main_list_layout.
4(d): MainListItemClickListener.java implements the itemclickListener where it gets the
various links from the corresponding rss_path
4(e):in RssReader.java it creates the available RSS item list from the RSS url and parses it
4(f): RssListAdapter.java , RssItemClickListener.java, RssItem.java and
RssParseHandler.java files are used to manage the rss link and when clicked on a particular item the
corresponding feeds are retrieved and displayed to the user.
Step 5:in the AndroidManifest.xml file use the uses-permission xml tag to give the internet
permission.
Step 6: Launch the application using the emulator then go to tools->android->android device
manager->emulator control. Send the location information to the emulator.
Step 7: Stop the program.
67
411719104053
PROGRAM CODING:
//RSS FEED
Main_Activity.java
package com.example.admin.rss;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import java.util.ArrayList;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar;
68
411719104053
import android.widget.Toast;
import java.util.ArrayList;
public class RssLoader extends AppCompatActivity {
Activity local;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rss_loader);
local = this;
progressBar = (ProgressBar) findViewById(R.id.progress);
Intent i = getIntent();
//gets the root intent
String title = i.getStringExtra("title");
//gets the String supplied with the tag title
String url = i.getStringExtra("link");
//gets the String supplied with the tag link
getRssData getRssData = new getRssData();
getRssData.execute(url);
//actionbar
getSupportActionBar().setTitle(title);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
protected void onPostExecute(ArrayList<RssItem> rssItems) {
if (rssItems != null) {
ListView rssList = (ListView) findViewById(R.id.lstRssFeed);
RssListAdapter adapter = new RssListAdapter(local, R.layout.rss_list_layout,
rssItems);
69
411719104053
rssList.setAdapter(adapter);
rssList.setOnItemClickListener(new RssItemClickListener(local, rssItems));
Toast.makeText(local, "Feed Loaded", Toast.LENGTH_SHORT).show();
} else
Toast.makeText(local, "Could not load feed. Check your network
connections.", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.INVISIBLE);
}
@Override
protected void onPreExecute() {
Toast.makeText(local, "Loading Feed", Toast.LENGTH_LONG).show();
}
}
}
MainListAdapter.java:
package com.example.admin.rss;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
Context context;
ArrayList<Course> list;
public MainListAdapter(Context context, int resource, ArrayList<Course> objects) {
super(context, resource, objects);
this.layoutResourceId = resource;
this.context = context;
this.list = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
MainListHolder holder = null;
if (row== null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new MainListHolder();
holder.indexTxt = (TextView) row.findViewById(R.id.txtIndex);
70
411719104053
}
static class MainListHolder
{
TextView indexTxt,titleTxt;
}
}
MainListItemClickListener.java:
package com.example.admin.rss;
import android.content.Intent;
import android.widget.AdapterView;
import android.view.View;
import android.app.Activity;
import java.util.ArrayList;
activity.startActivity(intent);
}
}
RssReader.java:
71
411719104053
package com.example.admin.rss;
import java.util.ArrayList;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
package com.example.admin.rss;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.widget.AdapterView;
import java.util.ArrayList;
import android.net.Uri;
import android.view.View;
}
public void setTitle(String title) {
this.title = title;
}
public String getLink(){
return link;
}
public void setLink(String link)
{
this.link=link;}
}
RssParseHandler.java
package com.example.admin.rss;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.ArrayList;
else if("title".equals(qName)){
parsingTitle = true;
}
else if("link".equals(qName)){
parsingLink = true;
}
//sets the current item to rss item when parsing item
//sets appropriate indicators to true when opening tags are processed
}
74
411719205032
@Override
public void endElement(String uri, String localName, String qName) throws
SAXException {
if ("item".equals(qName)){
rssItems.add(currentItem);
currentItem = null;
}
else if ("title".equals(qName)){
parsingTitle = false;
}
else if ("link".equals(qName)){
parsingLink = false;
}
//adds the current item to list
//sets appropriate indicators to false when closing tags are processed
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (parsingTitle){
if (currentItem!= null) {
currentItem.setTitle(new String(ch, start, length));
//sets titleof the currentitem
}
}
else if (parsingLink){
if (currentItem != null) {
currentItem.setLink(new String(ch, start, length));
}}}}
Course.java:
package com.example.admin.rss;
}
public String getUrl()
{
return url;
}
75
411719205032
}
76
411719205032
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.rss">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
activity_rss_loader.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="339dp"
android:layout_height="260dp"
android:id="@+id/lstRssFeed"
android:layout_gravity="center_horizontal" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="246dp"
android:layout_height="match_parent"
android:id="@+id/progress"
android:indeterminate="false" />
</LinearLayout>
77
411719205032
main_list_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="176dp"
android:layout_height="wrap_content"
android:text="INDEX"
android:id="@+id/txtIndex"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="138dp"
android:layout_height="0dp"
android:text="TITLE"
android:id="@+id/txtTitle"
android:layout_gravity="center_horizontal"
android:layout_weight="0.09" />
</LinearLayout>
rss_list_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TITLE"
android:id="@+id/txtTitle" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""http://www.example.com/post1""
android:id="@+id/txtLink" />
</LinearLayout>
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
78
411719205032
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.admin.rss.MainActivity"
tools:showIn="@layout/activity_main">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="43dp" />
</RelativeLayout>
79
411719205032
OUTPUT:
RESULT
Thus, the mobile application that makes use of RSS feed has been developed successfully.
80
411719205032
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingLeft="20dp" android:paddingRight="20dp" android:orientation="vertical" >
<EditText android:id="@+id/txtTo"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:hint="To"/>
<EditText android:id="@+id/txtSub"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="Subject"/>
<EditText>
android:id="@+id/txtMsg" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_weight="1" android:gravity="top"
android:hint="Message"/>
<Button android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_gravity="right" android:text="Send"
android:id="@+id/btnSend"/>
</LinearLayout>
81
411719205032
83
411719205032
OUTPUT:
Result:
Thus Android Application for sending an email is developed and executed successfully
84
411719205032
Aim
To develop a native calculator application.
Algorithm
Step 1: Start the program
Step 2: Open a new android project File → new →Android Application Project
Step 3: Output wizard in layout → activitymain.xml → graphical layout
Step 4: Design the required tool in the palette window
4(a):insert buttons for digits 0 to 9 and buttons for all the operators such as +,-,*,/,= and also
a button for clearing the plaintext field
4(b): insert plaintext for the input arithmetic expression
Step 5: Use F2 key to edit the name of the tools
Step 6: Open MainActivity.java file and type the code inside the class
6(a): set OnClickListener() method for each buttons to perform the function of that button
6(b): if the button is any operator perform the specified arithmetic operation on the inputs
given
6(c):display the computed output on the plain textfield
Step 7: Steps to create a emulator
7 (a): Got to menu Window → Android Virtual Device Manager
7(b): Select New → Type AVD name and click OK
Step 8: Stop the program
85
411719205032
PROGRAM CODING
//A NATIVE CALCULATOR APPLICATION
MainActivity.java
package com.example.admin.cal_harsh;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nine=(Button)findViewById(R.id.b9);
eig=(Button)findViewById(R.id.b8);
sev=(Button)findViewById(R.id.b7);
six=(Button)findViewById(R.id.b6);
fiv=(Button)findViewById(R.id.b5);
four=(Button)findViewById(R.id.b4);
thr=(Button)findViewById(R.id.b3);
two=(Button)findViewById(R.id.b2);
one=(Button)findViewById(R.id.b1);
zero=(Button)findViewById(R.id.b0);
dot=(Button)findViewById(R.id.bdot);
plus=(Button)findViewById(R.id.bplus);
min=(Button)findViewById(R.id.bsub);
div=(Button)findViewById(R.id.bdiv);
mul=(Button)findViewById(R.id.bmul);
eql=(Button)findViewById(R.id.beql);
clr=(Button)findViewById(R.id.bclr);
et=(EditText)findViewById(R.id.editText);
nine.setOnClickListener(this);
eig.setOnClickListener(this);
sev.setOnClickListener(this);
six.setOnClickListener(this);
fiv.setOnClickListener(this);
four.setOnClickListener(this);
thr.setOnClickListener(this);
two.setOnClickListener(this);
86
411719205032
one.setOnClickListener(this);
dot.setOnClickListener(this);
plus.setOnClickListener(this);
min.setOnClickListener(this);
div.setOnClickListener(this);
mul.setOnClickListener(this);
eql.setOnClickListener(this);
clr.setOnClickListener(this);
et.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.b0:
case R.id.b1:
case R.id.b2:
case R.id.b3:
case R.id.b4:
case R.id.b5:
case R.id.b6:
case R.id.b7:
case R.id.b8:
case R.id.b9:
case R.id.bdot:
inDigit = ((Button) v).getText().toString();
if (s.equals("0")) {
s = inDigit;
} else {
s += inDigit;
}
et.setText(s);
if (Io == '=') {
result = 0;
Io = ' ';
}
break;
case R.id.bplus:
compute();
Io = '+';
break;
case R.id.bsub:
compute();
Io = '-';
break;
case R.id.bmul:
compute();
Io = '*';
break;
case R.id.bdiv:
compute();
Io = '/';
break;
case R.id.beql:
87
411719205032
compute();
Io = '=';
break;
case R.id.bclr:
result = 0;
s = "0";
Io = ' ';
et.setText("0");
break;
}
}
}
et.setText(String.valueOf(result));
}
88
411719205032
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.admin.cal_harsh.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="calculator"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="@+id/textView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_marginTop="40dp"
android:text=" "
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="@+id/b0"
android:layout_marginTop="69dp"
android:layout_below="@+id/editText"
android:layout_toLeftOf="@+id/bdiv"
android:layout_toStartOf="@+id/bdiv" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/b1"
android:layout_alignTop="@+id/b0"
89
411719205032
android:layout_alignRight="@+id/textView"
android:layout_alignEnd="@+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/b2"
android:layout_alignTop="@+id/b1"
android:layout_toRightOf="@+id/b1"
android:layout_toEndOf="@+id/b1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="@+id/b4"
android:layout_alignTop="@+id/button"
android:layout_toLeftOf="@+id/b5"
android:layout_toStartOf="@+id/b5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/b5"
android:layout_alignTop="@+id/b4"
android:layout_alignLeft="@+id/b1"
android:layout_alignStart="@+id/b1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="@+id/b6"
android:layout_alignTop="@+id/b5"
android:layout_toRightOf="@+id/b5"
android:layout_toEndOf="@+id/b5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/b7"
android:layout_below="@+id/b4"
90
411719205032
android:layout_alignLeft="@+id/b4"
android:layout_alignStart="@+id/b4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/b8"
android:layout_alignTop="@+id/b7"
android:layout_toRightOf="@+id/b7"
android:layout_toEndOf="@+id/b7" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/b9"
android:layout_alignBottom="@+id/b8"
android:layout_toRightOf="@+id/b8"
android:layout_toEndOf="@+id/b8" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="clr"
android:id="@+id/bclr"
android:layout_below="@+id/b7"
android:layout_alignLeft="@+id/b7"
android:layout_alignStart="@+id/b7" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:id="@+id/bplus"
android:layout_below="@+id/b8"
android:layout_alignLeft="@+id/b5"
android:layout_alignStart="@+id/b5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:id="@+id/bsub"
android:layout_below="@+id/b9"
91
411719205032
android:layout_toRightOf="@+id/bplus"
android:layout_toEndOf="@+id/bplus" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_below="@+id/b2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="442dp"
android:layout_marginStart="442dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*"
android:id="@+id/bmul"
android:layout_below="@+id/bclr"
android:layout_alignLeft="@+id/bclr"
android:layout_alignStart="@+id/bclr" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="@+id/bdiv"
android:layout_above="@+id/beql"
android:layout_toRightOf="@+id/bmul"
android:layout_toEndOf="@+id/bmul" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="."
android:id="@+id/bdot"
android:layout_alignTop="@+id/bdiv"
android:layout_toRightOf="@+id/bdiv"
android:layout_toEndOf="@+id/bdiv" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="="
92
411719205032
android:id="@+id/beql"
android:layout_below="@+id/bmul"
android:layout_toRightOf="@+id/bmul"
android:layout_toEndOf="@+id/bmul" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/b3"
android:layout_above="@+id/b6"
android:layout_toRightOf="@+id/b2"
android:layout_toEndOf="@+id/b2" />
</RelativeLayout>
93
411719205032
OUTPUT
Expression:8*4=32
RESULT
Thus, the mobile application for a native calculator has been developed successfully.
94