Download as pdf or txt
Download as pdf or txt
You are on page 1of 97

GOVERNMENT POLYTECHNIC HISAR

APPROVED BY AICTE NEW DELHI, AFFILIATED HSBTE PANCHKULA

DEPARTMENT OF COMPUTER ENGINEERING

MOBILE APP DEVELOPMENT

LAB MANUAL

VI-SEMESTER

2023-2024

Prepared by:
Dr. Ajit Kumar
Contents

S. No Title Page No

1. Syllabus 3-3

2. Course objective 4-4

3. Do‟s & Don‟ts 4-4

4. List of Practicals 5-95

5. References 96-96
Syllabus

MOBILE APPLICATION DEVELOPMENT

SEMESTER – VI

IA Marks 25
Exam Marks50
Hours/Week 03 Hours Laboratory

LIST OF PRACTICLES

1. Write a program to demonstrate activity (Application Life Cycle)


2. Write a program to demonstrate different types of layouts
3. Write a program to implement simple calculator using text view, edit view, option
4. Write a program to demonstrate list view
5. Write a program to demonstrate photo gallery
6. Write a program to demonstrate Date picker and time picker
7. Develop a simple application with context menu and option menu
8. Develop an application to send SMS
9. Write a program to view, edit contact
10. Write a program to send e-mail
11. Write a program to demonstrate a service
12. Write a program to demonstrate web view to display web site
13. Write a program to display map of given location/position using map view
14. Write a program to demonstrate the application of intent class
15. Write a program to create a text file in a external memory
16. Write a program to store and fetch data from SQL lite database.
Course Objective:

This course offers a good understanding of cloud computing concepts and challenges faced in
implementation of cloud computing.

DOs and DON’Ts in Laboratory:

1. All the students should sit according to their roll numbers starting from their left to
right.

2. All the students are expected to get at least the algorithm of the program/ concept to
be implement.
3. Keep the lab neat and clean.
4. Do not interchange Mouse/Keyboard of terminals.
5. Do not touch electrical fitting in the lab.
6. Eating is strictly banned in the laboratory.
7. Shut down the computer before leaving.

8. Strictly follow the instructions given by the teacher/ Lab Instructor.


LIST OF PRACTICALS

S.No. Name of Practical Page No.


1 Write a program to demonstrate activity (Application Life Cycle). 6-10

2 Write a program to demonstrate different types of layouts. 11-18

3 Write a program to implement simple calculator using text view, 19-26


edit view, option button and button
4 Write a program to demonstrate list view 27-29

5 Write a program to demonstrate photo gallery 30-35

6 Write a program to demonstrate Date picker and time picker 36-39

7 Develop a simple application with context menu and option menu 40-45

8 Develop an application to send SMS 46-49

9 Write a program to view, edit contact 50-53

10 Write a program to send e-mail 54-58

11 Write a program to demonstrate a service 59-65

12 Write a program to demonstrate web view to display web site 66-68

13 Write a program to display map of given location/position using 69-74


map view
14 Write a program to demonstrate the application of intent class 75-78

15 Write a program to create a text file in a external memory 79-84

16 Write a program to store and fetch data from SQL lite database. 85-95
EXPERIMENT - 1

AIM - Write a program to demonstrate activity (Application Life Cycle).


THEORY -

Android Activity Lifecycle is controlled by 7 methods of android.app.Activity


class. The android Activity is the subclass of ContextThemeWrapper class. An
activity is the single screen in android. It is like window or frame of Java. By
the help of activity, you can place all your UI components or widgets in a single
screen.
The 7-lifecycle method of Activity describes how activity will behave at
different states.
Android Activity Lifecycle methods
An Activity in android application can take these states

1.Created – Activity is created

2.Running – Activity is visible and interacts with the user

3. Paused -Activity is still visible but partially obscured, instance is


running but might be killed by the system.

4. Stopped – Activity is not visible; instance is running but might be


killed by the system.

5. Destroyed -Activity has been terminated by the system of by a call


to its finish() method.

When an activity is first created its onCreate() method gets called then if the
subsequent onStart() method gets called and then the activity proceeds to its
onResume() method it here where the activity starts to run , now another
activity can come into foreground which forces this app to go into a paused state
, now either this activity can get killed by the os or get resumed or the activity
calls its onStop() method where the activity now goes into its Ondestroy()
method and get killed.
For more info go to –
http://developer.android.com/training/basics/activity-lifecycle/starting.html

Main Activity

package com.example.activity_life;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

@SuppressLint("NewApi")
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
notify("onCreate");
}

@Override
protected void onPause() {
super.onPause();
notify("onPause");
}

@Override
protected void onResume() {
super.onResume();
notify("onResume");
}

@Override
protected void onStop() {
super.onStop();
notify("onStop");
}

@Override
protected void onDestroy() {
super.onDestroy();
notify("onDestroy");
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
notify("onRestoreInstanceState");
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
notify("onSaveInstanceState");
}

private void notify(String methodName) {


String name = this.getClass().getName();
String[] strings = name.split("\\.");
Toast.makeText(getApplicationContext(),
methodName + "" + strings[strings.length - 1],
Toast.LENGTH_LONG).show();
}

}
OUTPUT –
EXPERIMENT – 2

AIM - Write a program to demonstrate different types of layouts

THEORY – A layout defines how your different components are shown on the
screen, a relative layout lets you arrange a component relative to another, while
Linear Layout lets you add components in a linear fashion. you can also define a
layout with another layout, according to your needs how you need to show
components on your main screen. The following code demonstrates defining a
linear layout within a Relative Layout.

1. Open eclipse or android studio and select new android project


2. Give project name and select next
3. Choose the android version. Choose the lowest android
version(Android 2.2) and select next
4. Enter the package name.package name must be two word separated by
comma and click finish
5. Go to package explorer in the left-hand side.select our project.
6. Go to res folder and select layout.Double click the main.xml file.

Activity_main -

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

android:id="@+id/relativeLayout1"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

<LinearLayout

android:id="@+id/linearLayout1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentRight="true"

android:layout_alignParentTop="true" >
<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:text="ADDITION"

android:textSize="20dp" >

</TextView>

</LinearLayout>

<LinearLayout

android:id="@+id/linearLayout2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentRight="true"

android:layout_below="@+id/linearLayout1" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="ENTER NO 1" >

</TextView>

<EditText

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="0.20"
android:id="@+id/edittext1"

android:inputType="number">

</EditText>

</LinearLayout>

<LinearLayout

android:id="@+id/linearLayout3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentRight="true"

android:layout_below="@+id/linearLayout2" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="ENTER NO 2" >

</TextView>

<EditText

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="0.20"

android:id="@+id/edittext2"

android:inputType="number">

</EditText>

</LinearLayout>
<LinearLayout

android:id="@+id/linearLayout4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentRight="true"

android:layout_below="@+id/linearLayout3" >

<Button

android:layout_width="wrap_content"

android:id="@+id/button1"

android:layout_height="wrap_content"

android:text="Addition"

android:layout_weight="0.50" />

<Button

android:layout_width="wrap_content"

android:id="@+id/button3"

android:layout_height="wrap_content"

android:text="subtraction"

android:layout_weight="0.50" />

<Button

android:layout_width="wrap_content"

android:id="@+id/button2"

android:layout_height="wrap_content"

android:text="CLEAR"
android:layout_weight="0.50" />

</LinearLayout>

<View

android:layout_height="2px"

android:layout_width="fill_parent"

android:layout_below="@+id/linearLayout4"

android:background="#DDFFDD"/>

</RelativeLayout>

Main Activity -

package layout.ne;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

public class LAYOUTActivity extends Activity {

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

EditText txtData1,txtData2;

float num1,num2,result1,result2;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button add = (Button) findViewById(R.id.button1);

add.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

try

txtData1 = (EditText) findViewById(R.id.edittext1);

txtData2 = (EditText) findViewById(R.id.edittext2);

num1 = Float.parseFloat(txtData1.getText().toString());

num2 = Float.parseFloat(txtData2.getText().toString());

result1=num1+num2;

Toast.makeText(getBaseContext(),"ANSWER:"+result1,Toast.LENGTH_SHO
RT).show();

catch(Exception e)

Toast.makeText(getBaseContext(), e.getMessage(),

Toast.LENGTH_SHORT).show();

});

Button sub = (Button) findViewById(R.id.button3);

sub.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

try
{

txtData1 = (EditText) findViewById(R.id.edittext1);

txtData2 = (EditText) findViewById(R.id.edittext2);

num1 = Float.parseFloat(txtData1.getText().toString());

num2 = Float.parseFloat(txtData2.getText().toString());

result2=num1-num2;

Toast.makeText(getBaseContext(),"ANSWER:"+result2,Toast.LENGTH_SHO
RT).show();

catch(Exception e)

Toast.makeText(getBaseContext(), e.getMessage(),

Toast.LENGTH_SHORT).show();

});

Button clear = (Button) findViewById(R.id.button2);

clear.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

try

txtData1.setText("");

txtData2.setText("");

catch(Exception e)
{

Toast.makeText(getBaseContext(), e.getMessage(),

Toast.LENGTH_SHORT).show();

} });

}}

Output:
EXPERIMENT – 3

AIM - Write a program to implement simple calculator using text view,


edit view, option button and button.
THEORY – Create a simple calculator which can perform basic arithmetic
operations like addition, subtraction, multiplication or division depending upon
the user input.

Source code & Steps:

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

<LinearLayout

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

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:id="@+id/linearLayout1"

android:layout_marginLeft="10pt"

android:layout_marginRight="10pt"

android:layout_marginTop="3pt">

<EditText

android:layout_weight="1"

android:layout_height="wrap_content"

android:layout_marginRight="5pt"
android:id="@+id/etNum1"

android:layout_width="match_parent"

android:inputType="numberDecimal">

</EditText>

<EditText

android:layout_height="wrap_content"

android:layout_weight="1"

android:layout_marginLeft="5pt"

android:id="@+id/etNum2"

android:layout_width="match_parent"

android:inputType="numberDecimal">

</EditText>

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:id="@+id/linearLayout2"

android:layout_marginTop="3pt"

android:layout_marginLeft="5pt"

android:layout_marginRight="5pt">

<Button

android:layout_height="wrap_content"

android:layout_width="match_parent"

android:layout_weight="1"
android:text="+"

android:textSize="15pt"

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

</Button>

<Button

android:layout_height="wrap_content"

android:layout_width="match_parent"

android:layout_weight="1"

android:text="-"

android:textSize="15pt"

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

</Button>

<Button

android:layout_height="wrap_content"

android:layout_width="match_parent"

android:layout_weight="1"

android:text="*"

android:textSize="15pt"

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

</Button>

<Button

android:layout_height="wrap_content"

android:layout_width="match_parent"

android:layout_weight="1"
android:text="/"

android:textSize="15pt"

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

</Button>

</LinearLayout>

<TextView

android:layout_height="wrap_content"

android:layout_width="match_parent"

android:layout_marginLeft="5pt"

android:layout_marginRight="5pt"

android:textSize="12pt"

android:layout_marginTop="3pt"

android:id="@+id/tvResult"

android:gravity="center_horizontal">

</TextView>

</LinearLayout>

MainActivity.java coding
package CALCU.CALU;

import android.app.Activity;

import android.os.Bundle;

import android.text.TextUtils;

import android.view.View;
import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

public class CALCULATORActivity extends Activity implements


OnClickListener {

EditText input1;

EditText input2;

Button addition;

Button subtraction;

Button multiplication;

Button division;

TextView tvResult;

String oper = "";

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

input1 = (EditText) findViewById(R.id.etNum1);

input2 = (EditText) findViewById(R.id.etNum2);

addition = (Button) findViewById(R.id.btnAdd);

subtraction = (Button) findViewById(R.id.btnSub);

multiplication = (Button) findViewById(R.id.btnMult);

division = (Button) findViewById(R.id.btnDiv);

tvResult = (TextView) findViewById(R.id.tvResult);


// set a listener

addition.setOnClickListener(this);

subtraction.setOnClickListener(this);

multiplication.setOnClickListener(this);

division.setOnClickListener(this);

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

float num1 = 0;

float num2 = 0;

float result = 0;

// check if the fields are empty

if (TextUtils.isEmpty(input1.getText().toString())

|| TextUtils.isEmpty(input2.getText().toString())) {

return;

// read EditText and fill variables with numbers num1

= Float.parseFloat(input1.getText().toString()); num2

= Float.parseFloat(input2.getText().toString());

// defines the button that has been clicked and performs the corresponding
operation

// write operation into oper, we will use it later for output

switch (v.getId()) {

case R.id.btnAdd:
oper = "+";

result = num1 + num2;

break;

case R.id.btnSub:

oper = "-";

result = num1 - num2;

break;

case R.id.btnMult:

oper = "*";

result = num1 * num2;

break;

case R.id.btnDiv:

oper = "/";

result = num1 / num2;

break;

default:

break;

// form the output line

tvResult.setText(num1 + " " + oper + " " + num2 + " = " + result);

}
OUTPUT:
EXPERIMENT – 4

AIM - Write a program to demonstrate list view.


THEORY – Android ListView is a view which groups several items and
display them in vertical scrollable list. The list items are automatically inserted
to the list using an Adapter that pulls content from a source such as an array or
database.
main activity file src/com.example.ListDisplay/ListDisplay.java. This file can
include each of the fundamental life cycle methods.
package com.example.ListDisplay;

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.widget.ArrayAdapter;

import android.widget.ListView;

public class ListDisplay extends Activity {


// Array of strings...
String[] mobileArray =
{"Android","IPhone","WindowsMobile","Blackberry",

"WebOS","Ubuntu","Windows7","Max OS X"};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ArrayAdapter adapter = new ArrayAdapter<String>(this,

R.layout.activity_listview, mobileArray);

ListView listView = (ListView) findViewById(R.id.mobile_list);

listView.setAdapter(adapter); }}
Following will be the content of res/layout/activity_main.xml file −

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

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context=".ListActivity" >

<ListView

android:id="@+id/mobile_list"

android:layout_width="match_parent

"

android:layout_height="wrap_content" >

</ListView>

</LinearLayout>

Following will be the content of res/values/strings.xml to define two new


constants −

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

<resources>

<string name="app_name">ListDisplay</string>

<string name="action_settings">Settings</string>

</resources>

Following will be the content of res/layout/activity_listview.xml file −

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

<!-- Single List Item Design -->

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dip"

android:textSize="16dip"

android:textStyle="bold" >

</TextView>

OUTPUT-
EXPERIMENT – 5

AIM - Write a program to demonstrate photo gallery.


THEORY -
Steps for Implementation of Android Gallery View:

1. Get the reference of Gallery in class using findViewById() method, or you


can also create an object dynamically.
2. Create an array of Images and call the adapter using Gallery view’s object.
3. Create a Custom adapter class which extends BaseAdapter to bind the
Gallery view with a series of ImageViews.

Important Methods of Gallery in Android:

Let’s we discuss some important methods of Gallery that may be called in order
to manage the Gallery.

1. setAnimationDuration(int): This method is used to set the duration for


how long a transition animation should run (in milliseconds) when layout has
changed.

Below we set the duration for how long a transition animation should run when
layout has changed.

Gallery simpleGallery = (Gallery) findViewById(R.id.simpleGallery); // get the


reference of Gallery

simpleGallery.setAnimationDuration(3000); // set 3000 milliseconds for


animation duration between items of Gallery
2. setSpacing(int): This method is used to set the spacing between items
in a Gallery.

Below we set the spacing between the items of Gallery.

Gallery simpleGallery = (Gallery) findViewById(R.id.simpleGallery); // get the


reference of Gallery

simpleGallery.setSpacing(5); // set space between the items of Gallery


3. setUnselectedAlpha(float): This method is used to set the alpha on the
items that are not selected.

Below we set the alpha value for unselected items of Gallery.

Gallery simpleGallery = (Gallery) findViewById(R.id.simpleGallery); // get the


reference of Gallery

simpleGallery.setUnselectedAlpha(0.80f); // set 0.25 value for the alpha of


unselected items of Gallery
Attributes of Gallery:

Now let’s we discuss some common attributes of a Gallery that helps us to


configure it in our layout (xml).

1. id: id attribute is used to uniquely identify a Gallery.

Below we set the id of the Gallery that is used to uniquely identify it.

<Gallery

android:id="@+id/simpleGallery"

android:layout_width="fill_parent"

android:layout_height="wrap_content"/ > < !-- id of Gallery used to uniquely


identify it -->

2. padding: This attribute is used to set the padding from left, right,
top or bottom side of a Gallery.

paddingRight: This attribute is used to set the padding from the right side of a
Gallery.

paddingLeft: This attribute is used to set the padding from the left side of a
Gallery.

paddingTop: This attribute is used to set the padding from the top side of a
Gallery.

paddingBottom: This attribute is used to set the padding from the bottom side
of a Gallery.

<Gallery

android:id="@+id/simpleGallery"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:padding="10dp"/> <!-- 10dp padding from all the sides of Gallery -->

3. background: This attribute is used to set the background of a Gallery.


We can set a color or a drawable in the background of a Gallery:
Below is the example code with explanation included in which we set the black
color in the background of Gallery.
<Gallery

android:id="@+id/simpleGallery"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="#000" /> <!-- black background color of Gallery -->

Setting padding In Gallery In Java class:

Gallery simpleGallery=(Gallery)findViewById(R.id.simpleGallery); // get the reference of


Gallery

simpleGallery.setBackgroundColor(Color.BLACK); // set black color in the background of


Gallery

4. animationDuration: This attribute is used to set the duration for how


long a transition animation should run (in milliseconds) when layout has
changed. We can also set the animation duration programmatically means in
java class by using setAnimationDuration(int).

Below we set the duration for how long a transition animation should run when
layout has changed.
<Gallery

android:id="@+id/simpleGallery"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:animationDuration="3000" />

5. spacing: This attribute is used to set the spacing between items in a Gallery.
We can also set the spacing between items programmatically means
in java class by using setSpacing() method.

Below we set the spacing between the items of Gallery.


<Gallery

android:id="@+id/simpleGallery"
android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:spacing="5dp" />

6. unselectedAlpha: This attribute is used to set the alpha on the items


that are not selected. Must be a floating point value, such as “5”. We can also
set the alpha of items programmatically means in java class by using
setUnselectedAlpha(float) method.

Below we set the alpha value for unselected items of Gallery.


<Gallery

android:id="@+id/simpleGallery"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:unselectedAlpha="0.25" />
EXPERIMENT – 6

AIM - Write a program to demonstrate Date picker and time picker.


THEORY –
Steps for demonstrating data picker and time picker are given below: -

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and
fill all required details to create a new project.

Step 2 − Add the following code to res/layout/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"
tools:context=".MainActivity">
<Button
android:id="@+id/btnPick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="Pick Date and TIme"/>
<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content
"
android:layout_centerInParent="true"
android:textSize="16sp"
android:textStyle="bold"/>
</RelativeLayout>

Step 3 − Add the following code to src/MainActivity.java


import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import java.util.Calendar;
public class MainActivity extends AppCompatActivity implements
DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {
TextView textView;
Button button;
int day, month, year, hour, minute;
int myday, myMonth, myYear, myHour, myMinute;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
button = findViewById(R.id.btnPick);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this,
MainActivity.this,year, month,day);
datePickerDialog.show(); } }); }
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
myYear = year;
myday = day;
myMonth = month;
Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR);
minute = c.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this,
MainActivity.this, hour, minute, DateFormat.is24HourFormat(this));
timePickerDialog.show(); }
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
myHour = hourOfDay;
myMinute = minute; textView.setText("Year:
" + myYear + "\n" +
"Month: " + myMonth + "\n" +
"Day: " + myday + "\n" +
"Hour: " + myHour + "\n" +
"Minute: " + myMinute); }}

Step 4 − Add the following code to androidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="app.com.sample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

OUTPUT –
EXPERIMENT – 7

AIM - Develop a simple application with context menu and option menu.

THEORY –

Android Context Menu: - Android context menu appears when user press long
clicks on the element. It is also known as floating menu. It affects the selected
content while doing action on it. It doesn't support item shortcuts and icons.

Android Option Menu: - Android Option Menus are the primary menus of
android. They can be used for settings, search, delete item etc. Here, we are
going to see two examples of option menus. First, the simple option menus and
second, options menus with images. Here, we are inflating the menu by calling
the inflate() method of MenuInflater class. To perform event handling on menu
items, you need to override onOptionsItemSelected() method of Activity
class\7.

Android Context Menu Example

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.androi
d.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"
tools:context="example.javatpoint.com.contextmenu.MainActivity">
<ListView
android:layout_width="368dp"
android:layout_height="495dp"
android:id="@+id/listView"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Activity class
package example.javatpoint.com.contextmenu;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


ListView listView;
String contacts[]={"Ajay","Sachin","Sumit","Tarun","Yogesh"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView=(ListView)findViewById(R.id.listView);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.si
mple_list_item_1,contacts);
listView.setAdapter(adapter);
// Register the ListView for Context menu
registerForContextMenu(listView);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.Contex
tMenuInfo menuInfo)
{
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
menu.setHeaderTitle("Select The Action");
}
@Override
public boolean onContextItemSelected(MenuItem item){
if(item.getItemId()==R.id.call){
Toast.makeText(getApplicationContext(),"calling code",Toast.LENGTH_LONG).
show();
}
else if(item.getItemId()==R.id.sms){
Toast.makeText(getApplicationContext(),"sending sms code",Toast.LENGTH_L
ONG).show();
}else{
return false;
}
return true;
}
}

Output:
Android Option Menu Example
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.c
om/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"
tools:context="example.javatpoint.com.optionmenu.MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />

File: context_main.xml

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


<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.androi
d.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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="example.javatpoint.com.optionmenu.MainActivity
" tools:showIn="@layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Activity class
package example.javatpoint.com.optionmenu;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id){
case R.id.item1:
Toast.makeText(getApplicationContext(),"Item 1
Selected",Toast.LENGTH_LONG).sh
ow();

r
e
t
ow();
u
r
n
t
ow();
r
u
e
;
}
c
a
s
e
R
.
i
d
.
i
t
e
m
2
:
Toast.makeText(getApplicationContext(),"Item 2
Selected",Toast.LENGTH_LONG).sh

r
e
t
u
r
n
t
r
u
e r
; e
c t
a u
s r
e n
R t
. r
i u
d e
. ;
i d
t e
e f
m a
3 u
: l
Toast.makeText(getApplicationContext(),"Item 3 t
Selected",Toast.LENGTH_LONG).sh
:
return super.onOptionsItemSelected(item);
}
}

Output:
EXPERIMENT – 8

AIM - Develop an application to send SMS.

THEORY – Manages SMS operations such as sending data, text, and pdu SMS
messages. Get this object by calling the static method getDefault(). To create an
instance of SMS Manager associated with a specific subscription ID,
call getSmsManagerForSubscriptionId(int). This is typically used for devices
that support multiple active subscriptions at once.

activity_main.xml
<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent
" tools:context=".MainActivity" >

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:ems="10" />

<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1
" android:layout_below="@+id/editText1"
android:layout_marginTop="26dp"
android:ems="10"
android:inputType="textMultiLine" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_toLeftOf="@+id/editText1"
android:text="Mobile No:" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content
"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignLeft="@+id/textView1"
android:text="Message:" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText2"
android:layout_below="@+id/editText2"
android:layout_marginLeft="34dp"
android:layout_marginTop="48dp"
android:text="Send SMS" />
</RelativeLayout>

You need to write SEND_SMS permission as given below:

<uses-permission android:name="android.permission.SEND_SMS"/>

Activity class
package com.example.sendsms;
import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
EditText mobileno,message;
Button sendsms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mobileno=(EditText)findViewById(R.id.editText1);
message=(EditText)findViewById(R.id.editText2);
sendsms=(Button)findViewById(R.id.button1);
//Performing action on button click
sendsms.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String no=mobileno.getText().toString();
String msg=message.getText().toString();
//Getting intent and PendingIntent instance
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, intent,0);
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, pi,null);
Toast.makeText(getApplicationContext(), "Message Sent successfully!",
Toast.LENGTH_LONG).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}}

Output:
EXPERIMENT – 9

AIM - Write a program to view, edit contact.

THEORY - use an Intent to insert a new contact or modify a contact's data.


Instead of accessing the Contacts Provider directly, an Intent starts the contacts
app, which runs the appropriate Activity. For the modification actions described
in this lesson, if you send extended data in the Intent it's entered into the UI of
the Activity that is started.

Step 1 Create ContactHelper class.


First we create ContactHelper class into our project. In this class we create methods for
Getting , Adding and Deleting contacts.

Step 2 Read Contacts


Add this method in to ContactHelper class for getting all the Contacts. This
method returns the cursor of all the contacts.

public static Cursor getContactCursor(ContentResolver contactHelper, String startsWith) {

String[] projection = { ContactsContract.CommonDataKinds.Phone._ID,


ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER };

Cursor cur = null;

try {

if (startsWith != null && !startsWith.equals("")) {

cur = contactHelper.query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI,


projection, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " like \"" +
startsWith + "%\"", null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + "
ASC");

} else {

cur = contactHelper.query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI,


projection, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + "
ASC");

cur.moveToFirst();
}

catch (Exception e) {

e.printStackTrace();

return cur;

Step 3 Insert Contacts


Add this method in to ContactHelper.java class for adding the Contacts. This
method returns the boolean value with contact addition done.

public static boolean insertContact(ContentResolver contactAdder, String firstName, String


mobileNumber) {

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_U
RI).withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,
null).withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null).build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).with
ValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,
0).withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Stru
cturedName.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.Str
ucturedName.GIVEN_NAME,firstName).build());

ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).with
ValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,
0).withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Pho
ne.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.Phone.NUM
BER,mobileNumber).withValue(ContactsContract.CommonDataKinds.Phone.TYPE,Phone.
TYPE_MOBILE).build());

try {

contactAdder.applyBatch(ContactsContract.AUTHORITY, ops);

} catch (Exception e) {

return false;

return true;
}

Step 4 Delete Contacts


Add this method in to ContactHelper class for deleting the Contacts. In this method we need
Contact ID so, we use one another method for getting Contact ID.

public static void deleteContact(ContentResolver contactHelper, String number) {

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

String[] args = new String[] { String.valueOf(getContactID(contactHelper, number)) };

ops.add(ContentProviderOperation.newDelete(RawContacts.CONTENT_URI).withSelection
(RawContacts.CONTACT_ID + "=?", args).build());

try {

contactHelper.applyBatch(ContactsContract.AUTHORITY, ops);

} catch (RemoteException e) {

e.printStackTrace();

} catch (OperationApplicationException e) {

e.printStackTrace();

private static long getContactID(ContentResolver contactHelper,String number) {

Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,


Uri.encode(number));

String[] projection = { PhoneLookup._ID };

Cursor cursor = null;

try {

cursor = contactHelper.query(contactUri, projection, null, null,null);

if (cursor.moveToFirst()) {

int personID = cursor.getColumnIndex(PhoneLookup._ID);

return cursor.getLong(personID);
}

return -1;

} catch (Exception e) {

e.printStackTrace();

} finally {

if (cursor != null) {

cursor.close();

cursor = null;

return -1;

OUTPUT –
EXPERIMENT-10

AIM - Write a program to send e-mail.

THEORY - To send an email from your application, you don’t have to


implement an email client from the beginning, but you can use an existing one
like the default Email app provided from Android, Gmail, Outlook, K-9 Mail
etc. For this purpose, we need to write an Activity that launches an email client,
using an implicit Intent with the right action and data. In this example, we are
going to send an email from our app by using an Intent object that launches
existing email clients.

Source code -
package com.example.programtosendmail;

import android.net.Uri;

import android.os.Bundle;

import android.app.Activity;

import android.content.Intent;

import android.util.Log;

import android.view.Menu;

import android.view.View;

import android.widget.Button;

import android.widget.Toast;\

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button startBtn = (Button) findViewById(R.id.sendEmail);

startBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {

sendEmail();

});

protected void sendEmail() {

Log.i("Send email", "");

String[] TO = {""};

String[] CC = {""};

Intent emailIntent = new Intent(Intent.ACTION_SEND);

emailIntent.setData(Uri.parse("mailto:"));

emailIntent.setType("text/plain");

emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);

emailIntent.putExtra(Intent.EXTRA_CC, CC);

emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");

emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");

try {

startActivity(Intent.createChooser(emailIntent, "Send mail..."));

finish();

Log.i("Finished sending email...", "");


} catch (android.content.ActivityNotFoundException ex) {

Toast.makeText(MainActivity.this, "There is no email client installed.",

Toast.LENGTH_SHORT).show();

XML CODE -
<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/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Sending Mail Example"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true

" android:textSize="30dp" />

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content

" android:text=" programtosendmail"

android:textColor="#ff87ff09"

android:textSize="30dp"

android:layout_above="@+id/imageButton"

android:layout_alignRight="@+id/imageButton"

android:layout_alignEnd="@+id/imageButton" />

<ImageButton

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/imageButton"

android:src="@drawable/abc"
android:layout_centerVertical="true"

android:layout_centerHorizontal="true" />

<Button

android:id="@+id/sendEmail"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/compose_email"/>

</LinearLayout>

Following will be the content of res/values/strings.xml to define two new constants −

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

<resources>

<string name="app_name"> programtosendmail </string>

<string name="compose_email">Compose Email</string>

</resources>

Following is the default content of AndroidManifest.xml −

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

<manifest

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

package="com.example. programtosendmail " >

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher

" android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name="com.example.

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

OUTPUT –
EXPERIMENT – 11

AIM - Write a program to demonstrate a service.

THEORY - Android service is a component that is used to perform operations


on the background such as playing music, handle network transactions,
interacting content providers etc. It doesn't have any UI (user interface).

The service runs in the background indefinitely even if application is destroyed.

Moreover, service can be bounded by a component to perform interactivity and


inter process communication (IPC).
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.javatpoint.com.androidservice.MainActivity">

<Button
android:id="@+id/buttonStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="74dp"
android:text="Start Service" />

<Button
android:id="@+id/buttonStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Stop Service" />
<Button
android:id="@+id/buttonNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="63dp"
android:text="Next Page" />
</RelativeLayout>
activity_next.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.androi
d.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"
tools:context="example.javatpoint.com.androidservice.NextPage">

<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="200dp"
android:text="Next Page"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
Service class
package example.javatpoint.com.androidservice;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.widget.Toast;
public class MyService extends Service {
MediaPlayer myPlayer;
@Nullable
@Override
public IBinder onBind(Intent intent) {

return null;
}
@Override
public void onCreate() {
Toast.makeText(this, "Service Created", Toast.LENGTH_LONG).show();
myPlayer = MediaPlayer.create(this, R.raw.sun);
myPlayer.setLooping(false); // Set looping
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
myPlayer.start();
}
@Override
public void onDestroy() {
Toast.makeText(this, "Service Stopped", Toast.LENGTH_LONG).show();
myPlayer.stop();
}
}
Activity class
package example.javatpoint.com.androidservice;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity implements View.OnClickListe
ner{
Button buttonStart, buttonStop,buttonNext;
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonStart = findViewById(R.id.buttonStart);
buttonStop = findViewById(R.id.buttonStop);
buttonNext = findViewById(R.id.buttonNext);
buttonStart.setOnClickListener(this);
buttonStop.setOnClickListener(this);
buttonNext.setOnClickListener(this);
}

public void onClick(View src) {


switch (src.getId()) {
case R.id.buttonStart:
startService(new Intent(this, MyService.class));
break;
case R.id.buttonStop:
stopService(new Intent(this, MyService.class));
break;
case R.id.buttonNext:
Intent intent=new Intent(this,NextPage.class);
startActivity(intent);
break;
}
}
}
NextPage class
package example.javatpoint.com.androidservice;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class NextPage extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next);
}

}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.javatpoint.com.androidservice">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NextPage"></activity>
<service
android:name=".MyService"
android:enabled="true" />
</application>

</manifest>

Output:
EXPERIMENT – 12

AIM - Write a program to demonstrate web view to display web site.

THEORY - Android WebView is used to display web page in android. The web
page can be loaded from same application or URL. It is used to display online
content in android activity. Android WebView uses webkit engine to display
web page. The android.webkit.WebView is the subclass of AbsoluteLayout
class.

Here is an example demonstrating the use of WebView Layout. It creates a basic


web application that will ask you to specify a URL and will load this URL
website in the WebView.
activity_main.xml

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

2. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.and
roid.com/apk/res/android"

3. xmlns:app="http://schemas.android.com/apk/res-auto"

4. xmlns:tools="http://schemas.android.com/tools"

5. android:layout_width="match_parent"

6. android:layout_height="match_parent"

7. tools:context="example.javatpoint.com.webview.MainActivity">

8.​

9. <WebView

10. android:layout_width="match_parent"

11. android:layout_height="match_parent"

12. android:id="@+id/webView"

13. app:layout_constraintBottom_toBottomOf="parent"

14. app:layout_constraintLeft_toLeftOf="parent"

15. app:layout_constraintRight_toRightOf="parent"

16. app:layout_constraintTop_toTopOf="parent" />


17.​

18. </android.support.constraint.ConstraintLayout>

To add the web page (.html, .jsp) locally in application, they are required to place in the assets
folder. An assets folder is created as: right click on app -> New -> Folder -> Assets Folder -
>main or simply create an assets directory inside main directory.

Activity class

1. package example.javatpoint.com.webview;

2.​

3. import android.support.v7.app.AppCompatActivity;

4. import android.os.Bundle;

5. import android.webkit.WebView;

6.​

7. public class MainActivity extends

AppCompatActivity { 8.

9. @Override

10. protected void onCreate(Bundle savedInstanceState) {

11. super.onCreate(savedInstanceState);

12. setContentView(R.layout.activity_main);

13. WebView mywebview = (WebView) findViewById(R.id.webView);

14. // mywebview.loadUrl("https://www.javatpoint.com/");

15.​

16. /*String data = "<html><body><h1>Hello, Javatpoint!</h1></body></html>";

17. mywebview.loadData(data, "text/html", "UTF-8"); */

18.

19. mywebview.loadUrl("file:///android_asset/myresource.html");

20. }

21. }
Output:
EXPERIMENT – 13

AIM - Write a program to display map of given location/position using


map view.

THEORY – Here are some steps to demonstrate the use of map view –

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and
fill all required details to create a new project.

Step 2 − Add the following code to res/layout/activity_main.xml.


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

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

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/myMap"

android:name="com.google.android.gms.maps.SupportMapFragment"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity" />

Step 3 – Add the following dependency in the build.gradle (Module: app)

implementation 'com.google.android.gms:play-services-maps:17.0.0'

implementation 'com.google.android.gms:play-services-location:17.0.0'

Step 4 − Add the following code to src/MainActivity.java


import android.Manifest;

import android.content.pm.PackageManager;

import android.location.Location;

import android.os.Bundle;

import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;

import com.google.android.gms.maps.SupportMapFragment;

import com.google.android.gms.location.FusedLocationProviderClient;

import com.google.android.gms.location.LocationServices;

import com.google.android.gms.maps.GoogleMap;

import com.google.android.gms.maps.OnMapReadyCallback;

import com.google.android.gms.maps.model.LatLng;

import com.google.android.gms.maps.model.MarkerOptions;

import com.google.android.gms.tasks.OnSuccessListener;

import com.google.android.gms.tasks.Task;

import androidx.annotation.NonNull;

import androidx.core.app.ActivityCompat;

import androidx.fragment.app.FragmentActivity;

public class MainActivity extends FragmentActivity implements OnMapReadyCallback {

Location currentLocation;

FusedLocationProviderClient fusedLocationProviderClient;

private static final int REQUEST_CODE = 101

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);

fetchLocation();

private void fetchLocation() {

if (ActivityCompat.checkSelfPermission(
this, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(

this, Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE);

return;

Task<Location> task = fusedLocationProviderClient.getLastLocation();

task.addOnSuccessListener(new OnSuccessListener<Location>() {

@Override

public void onSuccess(Location location) {

if (location != null) {

currentLocation = location;

Toast.makeText(getApplicationContext(), currentLocation.getLatitude() + "" +


currentLocation.getLongitude(), Toast.LENGTH_SHORT).show();

SupportMapFragment supportMapFragment = (SupportMapFragment)


getSupportFragmentManager().findFragmentById(R.id.myMap);

assert supportMapFragment != null;

supportMapFragment.getMapAsync(MainActivity.this);

}); }

@Override

public void onMapReady(GoogleMap googleMap) {

LatLng latLng = new LatLng(currentLocation.getLatitude(),


currentLocation.getLongitude());

MarkerOptions markerOptions = new MarkerOptions().position(latLng).title("I am


here!");

googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 5));

googleMap.addMarker(markerOptions);

@Override

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,


@NonNull int[] grantResults) {

switch (requestCode) {

case REQUEST_CODE:

if (grantResults.length > 0 && grantResults[0] ==


PackageManager.PERMISSION_GRANTED) {

fetchLocation();

break;

Step 5 – Open strings.xml and add the following code −


<resources>

<string name="app_name">Sample</string>

<string name="map_key" translatable="false">Enter your google API key here</string>

</resources>

Step 6 – To get the google API key (map_key), kindly follow the steps below

Visit the Google Cloud Platform Console.

● Click the project drop-down and select or create the project for which you
want to add an API key.

● Click the menu button and select APIs & Services > Credentials.

● On the Credentials page, click Create credentials > API key. The API key
created dialog displays your newly created API key.
● Click Close.

● The new API key is listed on the Credentials page under API keys.
(Remember to restrict the API key before using it in production.)

Step 7 − Add the following code to androidManifest.xml


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

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="app.com.sample">

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher

" android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

<meta-data android:name="com.google.android.geo.API_KEY"
android:value="@string/map_key"/>

<activity android:name=".MainActivity">

<intent-filter>

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

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

</intent-filter>

</activity>

</application>

</manifest>
Output -
EXPERIMENT – 14

AIM – Write a program to demonstrate the application of intent class.

THEORY – Android Intent is the message that is passed between components


such as activities, content providers, broadcast receivers, services etc.

It is generally used with startActivity() method to invoke activity, broadcast


receivers etc. The dictionary meaning of intent is intention or purpose. So, it can
be described as the intention to do action. The LabeledIntent is the subclass of
android.content.Intent class. Android intents are mainly used to:

o Start the service


o Launch an activity
o Display a web page
o Display a list of contacts
o Broadcast a message
o Dial a phone call etc.
o

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.co
m/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"
tools:context="example.javatpoint.com.implicitintent.MainActivity"
>

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="60dp"
android:ems="10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.575"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_marginLeft="156dp"
android:layout_marginTop="172dp"
android:text="Visit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/editText" />
</android.support.constraint.ConstraintLayout>

Activity class
package example.javatpoint.com.implicitintent;
import android.content.Intent;
import android.net.Uri;
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 {

Button button;
EditText editText;

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

button = findViewById(R.id.button);
editText = findViewById(R.id.editText);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url=editText.getText().toString();
Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});
}
}
Output –
EXPERIMENT – 15

AIM - Write a program to create a text file in an external memory.


THEORY – Here are some steps to demonstrate the given Experiment: -
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and
fill all required details to create a new project.
Step 2 − Add the following code to res/layout/activity_main.xml.
<?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 = ".MainActivity"
android:orientation = "vertical">
<EditText
android:id = "@+id/enterText"
android:hint = "Please enter text here"
android:layout_width = "match_parent"
android:layout_height = "wrap_content" />
<Button

android:id = "@+id/save"
android:text = "Save"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content" />
</LinearLayout>

In the above code, we have taken edit text and button. When user click on
button, it will take data from edit text and store in external storage.
Step 3 − Add the following code to src/MainActivity.java
package com.example.andy.myapplication;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
private static final int PERMISSION_REQUEST_CODE = 100;
Button save;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText enterText = findViewById(R.id.enterText);
save = findViewById(R.id.save);
save.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {


if (!enterText.getText().toString().isEmpty()) {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
if (Build.VERSION.SDK_INT > = 23) {
if (checkPermission()) {
File sdcard = Environment.getExternalStorageDirectory();
File dir = new File(sdcard.getAbsolutePath() + "/text/");
dir.mkdir();
File file = new File(dir, "sample.txt");
FileOutputStream os = null;
try {

os = new FileOutputStream(file);
os.write(enterText.getText().toString().getBytes());
os.close();
} catch (IOException e) {
e.printStackTrace();
}

} else {
requestPermission(); // Code for permission
}
} else {
File sdcard = Environment.getExternalStorageDirectory();
File dir = new File(sdcard.getAbsolutePath() + "/text/");
dir.mkdir();
File file = new File(dir, "sample.txt");
FileOutputStream os = null;
try {

os = new FileOutputStream(file);
os.write(enterText.getText().toString().getBytes());
os.close();
} catch (IOException e) {
e.printStackTrace();
} }
} }
} }); }
private boolean checkPermission() {
int result = ContextCompat.checkSelfPermission(MainActivity.this,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (result = = PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
} }
private void requestPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Toast.makeText(MainActivity.this, "Write External Storage permission allows us to
create files. Please allow this permission in App Settings.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(MainActivity.this, new
String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE},
PERMISSION_REQUEST_CODE);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[]
grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] = =
PackageManager.PERMISSION_GRANTED) {
Log.e("value", "Permission Granted, Now you can use local drive .");
} else {
Log.e("value", "Permission Denied, You cannot use local drive .");
}
break;
} } }

Step 4 − Add the following code to manifest.xml


<?xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns:android = "http://schemas.android.com/apk/res/android"
package = "com.example.andy.myapplication">
<uses-permission android:name =
"android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name =
"android.permission.READ_EXTERNAL_STORAGE"/
>
<application
android:allowBackup = "true"
android:icon = "@mipmap/ic_launcher"
android:label = "@string/app_name"
android:roundIcon = "@mipmap/ic_launcher_round"
android:supportsRtl = "true"
android:theme = "@style/AppTheme">

<activity android:name = ".MainActivity">


<intent-filter>
<action android:name = "android.intent.action.MAIN" />
<category android:name = "android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
OUTPUT –
EXPERIMENT – 16

AIM – Write a program to store and fetch data from SQL lite database.
THEORY – SQLite is an open-source relational database i.e., used to perform
database operations on android devices such as storing, manipulating or
retrieving persistent data from the database.
It is embedded in android by default. So, there is no need to perform any
database setup or administration task.
The android.database.sqlite.SQLiteOpenHelper class is used for database
creation and version management. For performing any database operation, you
have to provide the implementation of onCreate() and onUpgrade() methods of
SQLiteOpenHelper class.

Source code :

<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="@string/title"

android:layout_x="110dp"

android:layout_y="10dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

<TextView android:text="@string/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="@string/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="@string/salary"

android:layout_x="30dp"

android:layout_y="150dp"

android:layout_width="wrap_content"

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="@string/add"

android:layout_x="30dp"

android:layout_y="200dp"

android:layout_width="130dp"

android:layout_height="40dp"/>

<Button android:id="@+id/btnDelete"

android:text="@string/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="@string/modify"

android:layout_x="30dp"
android:layout_y="250dp"

android:layout_width="130dp"

android:layout_height="40dp"/>

<Button android:id="@+id/btnView"

android:text="@string/view"

android:layout_x="160dp"

android:layout_y="250dp"

android:layout_width="130dp"

android:layout_height="40dp"/>

<Button android:id="@+id/btnViewAll"

android:text="@string/view_all"

android:layout_x="85dp"

android:layout_y="300dp"

android:layout_width="150dp"

android:layout_height="40dp"/>

</AbsoluteLayout>

Go to values folder and select string.xml file.Replace the code below

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

<resources>

<string name="app_name">Employee detail1</string>

<string name="hello">Hello World, Employee detail Activity!</string>

<string name="title">Employee Details</string>

<string name="empid">Enter Employee ID: </string>

<string name="name">Enter Name: </string>

<string name="salary">Enter salary: </string>


<string name="add">Add Employee</string>

<string name="delete">Delete Employee</string>

<string name="modify">Modify Employee</string>

<string name="view">View Employee</string>

<string name="view_all">View All Employee</string>

</resources>

8) Now select mainactivity.java file and type the following code.In my coding maniactivity name

is EmployeedetailActivity.

package employee.detail;

//import android.R;

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 EmployeedetailActivity extends Activity implements OnClickListener {

EditText editEmpid,editName,editsalary;

Button btnAdd,btnDelete,btnModify,btnView,btnViewAll;

SQLiteDatabase db;

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

@Override

public void onCreate(Bundle savedInstanceState)


{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

editEmpid=(EditText)findViewById(R.id.editEmpid);

editName=(EditText)findViewById(R.id.editName);

editsalary=(EditText)findViewById(R.id.editsalary);

btnAdd=(Button)findViewById(R.id.btnAdd);

btnDelete=(Button)findViewById(R.id.btnDelete);

btnModify=(Button)findViewById(R.id.btnModify);

btnView=(Button)findViewById(R.id.btnView);

btnViewAll=(Button)findViewById(R.id.btnViewAll);

btnAdd.setOnClickListener(this);

btnDelete.setOnClickListener(this);

btnModify.setOnClickListener(this);

btnView.setOnClickListener(this);

btnViewAll.setOnClickListener(this);

db=openOrCreateDatabase("EmployeeDB", Context.MODE_PRIVATE, null);

db.execSQL("CREATE TABLE IF NOT EXISTS employee(empid VARCHAR,name

VARCHAR,salary VARCHAR);");

public void onClick(View view)

if(view==btnAdd)

if(editEmpid.getText().toString().trim().length()==0||

editName.getText().toString().trim().length()==0||

editsalary.getText().toString().trim().length()==0)
{

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

return;

db.execSQL("INSERT INTO employee

VALUES('"+editEmpid.getText()+"','"+editName.getText()+

"','"+editsalary.getText()+"');");

showMessage("Success", "Record added");

clearText();

if(view==btnDelete)

if(editEmpid.getText().toString().trim().length()==0)

showMessage("Error", "Please enter Employee id");

return;

Cursor c=db.rawQuery("SELECT * FROM employee WHERE

empid='"+editEmpid.getText()+"'", null);

if(c.moveToFirst())

db.execSQL("DELETE FROM employee WHERE

empid='"+editEmpid.getText()+"'");

showMessage("Success", "Record Deleted");

else

{
showMessage("Error", "Invalid Employee id");

clearText();

if(view==btnModify)

if(editEmpid.getText().toString().trim().length()==0)

showMessage("Error", "Please enter Employee id");

return;

Cursor c=db.rawQuery("SELECT * FROM employee WHERE

empid='"+editEmpid.getText()+"'", null);

if(c.moveToFirst())

db.execSQL("UPDATE employee SET

name='"+editName.getText()+"',salary='"+editsalary.getText()

+ "' WHERE empid='"+editEmpid.getText()+"'");

showMessage("Success", "Record Modified");

else

showMessage("Error", "Invalid Rollno");

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

editEmpid.setText("");

editName.setText("");

editsalary.setText("");

editEmpid.requestFocus();

}
OUTPUT:
REFERENCES

1. ANDROID DEVELOPERS OFFICIAL WEBSITE: -

https://developer.android.com/

2. TUTORIALS POINT WEBSITE: -

https://www.tutorialspoint.com/android/

3. GEEKFORGEEKS WEBSITE: -

https://www.geeksforgeeks.org/

4. JAVATPONT WEBSITE: -

https://www.javatpoint.com/

5. STACKOVERFLOW WEBSITE: -

https://stackoverflow.com/

You might also like