0% found this document useful (0 votes)
3 views110 pages

Android GUI Components Tutorial

The document outlines the development of an Android application using GUI components, fonts, colors, layout managers, and event listeners. It includes detailed procedures for creating various activities, designing layouts, and implementing functionality through Java code. The final result is an application that effectively showcases the use of these elements within the Android Studio framework.

Uploaded by

palanisamy.cse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views110 pages

Android GUI Components Tutorial

The document outlines the development of an Android application using GUI components, fonts, colors, layout managers, and event listeners. It includes detailed procedures for creating various activities, designing layouts, and implementing functionality through Java code. The final result is an application that effectively showcases the use of these elements within the Android Studio framework.

Uploaded by

palanisamy.cse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

EXNO:01

DATE: GUI COMPONENTS FONT AND COLOURS

AIM: To develop an application that uses GUI components, font and


colors using android studio mobile application development
framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends AppCompatActivity parent class.

Step2: Design the application using GUI Components such as


TextView, Button, ImageButton, RadioButton, CheckBox,
ToggleButton.

Step3: Relate the functionality of fonts with radio button in the


java class file using onclick method.

Step4: Relate the functionality of changing colors with checkbox


in the java class file using onclick method.

Step5: Display the text as a message using Toast widget.

Step6: Display the version history of android using ImageView


widget and relate its functionality with a toggle button.

Step7: Replace the default launcher icon with new icon using
Asset Studio wizard.

Step8: Run the android application on an emulator.

1
PROGRAM:

<! -- activity_intro.xml - - >


<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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=".IntroActivity">

<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical">

<LinearLayout
android:id="@+id/introduction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/title_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ANDROID"

android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/intro_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/intro_content"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/release_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="Latest Release"

2
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageButton
android:id="@+id/latest_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="onreleaseClick"
android:src="@drawable/marshmallow" />

<TextView
android:id="@+id/font_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Change Font"
android:textAppearance="?android:attr/textAppearanceLarge" />

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<RadioButton
android:id="@+id/candella_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="changeFont"
android:text="Candella" />

<RadioButton
android:id="@+id/stencil_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="changeFont"
android:text="Stencil" />

<RadioButton
android:id="@+id/alex_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="changeFont"
android:text="Alex" />
</RadioGroup>

<TextView
android:id="@+id/color_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

3
android:layout_marginTop="10dp"
android:text="Change Color"
android:textAppearance="?android:attr/textAppearanceLarge" />

<CheckBox
android:id="@+id/charcoal_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="changeColor"
android:text="Foreground" />

<CheckBox
android:id="@+id/greenish_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="changeColor"
android:text="Background" />

<ToggleButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:onClick="onchangeState"
android:textOff="Display Version History"
android:textOn="Android Version History" />

<ImageView
android:id="@+id/version_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />

</LinearLayout>
</ScrollView>
</LinearLayout>

// [Link]

package [Link].android_intro;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

4
import [Link];
import [Link];

public class IntroActivity extends AppCompatActivity {


private TextView title, content;
private Typeface candella_font, stencil_font, alex_font;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_intro);
title = (TextView) findViewById([Link].title_txt);
content = (TextView) findViewById([Link].intro_txt);
candella_font = [Link](getAssets(), "[Link]");
stencil_font = [Link](getAssets(), "[Link]");
alex_font = [Link](getAssets(), "[Link]");
}

public void onreleaseClick(View view) {


[Link](getApplicationContext(), "Android 6.0 Marshmallow
released on October 5, 2015", Toast.LENGTH_LONG).show();
}

public void changeFont(View view) {


boolean Rflag = ((RadioButton) view).isChecked();
switch ([Link]()) {
case [Link].candella_btn:
if (Rflag) {
[Link](candella_font);
[Link](candella_font);
}
break;
case [Link].stencil_btn:
if (Rflag) {
[Link](stencil_font);
[Link](stencil_font);
}
break;
case [Link].alex_btn:
if (Rflag) {
[Link](alex_font);
[Link](alex_font);
}
break;
}
}

public void changeColor(View view) {


boolean Cflag = ((CheckBox) view).isChecked();

5
switch ([Link]()) {
case [Link].charcoal_txt:
if (Cflag) {
[Link]([Link]("#FF0000"));
[Link]([Link]("#FF0000"));
} else {
[Link]([Link]("#000000"));
[Link]([Link]("#000000"));
}
break;
case [Link].greenish_txt:
if (Cflag) {
[Link]([Link]("#FFFFAA"));
[Link]([Link]("#FFFFAA"));
} else {
[Link]([Link]("#FFFFFF"));
[Link]([Link]("#FFFFFF"));
}
break;
}
}

public void onchangeState(View view) {


ImageView versions = (ImageView) findViewById([Link].version_image);
boolean tflag = ((ToggleButton) view).isChecked();
if (tflag) {
[Link]([Link].android_versions);
[Link]([Link]);
} else {
[Link]([Link]);
}
}
}

OUTPUT:

6
RESULT: Thus an android mobile application that uses GUI
components, font and colors was developed and executed.

EXNO:02

7
DATE: LAYOUT MANAGERS AND EVENT LISTENERS

AIM: To develop an application that uses Layout Managers and


Event listeners using android studio mobile application
development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends AppCompatActivity parent class.

Step2: Design the launcher activity with relative layout and add
widgets such as TextView, Button, ImageView.

Step3: Create new activity with linear layout and add


corresponding TextView widgets.

Step4: Create new activity with grid layout and add corresponding
TextView widgets.

Step5: Create new activity with frame layout and add


corresponding ImageView widgets.

Step6: Relate each activity with the launcher activity using a


button widget.

Step7: Define event listener for each button widget.

Step8: Invoke different activities from the event listener using


intent class.

Step9: Mention the details of each activity inside the intent


filter tag of [Link] file

Step10: Replace the default launcher icon with new icon using
Asset Studio wizard.

Step11: Run the android application on an emulator.

PROGRAM:

8
<!— activity_cahcet.xml 

<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
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=".CahcetActivity">

<TextView
android:id="@+id/cahcet_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:text="@string/college_name"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/cahcetlogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cahcet_txt"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:src="@drawable/cahcet_logo" />

<TextView
android:id="@+id/moto_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cahcetlogo"
android:layout_centerHorizontal="true"
android:text="Enter to [Link] to Serve"
android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
android:id="@+id/recognition_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/moto_txt"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:text="Accredited by NBA and NAAC - A Grade"

9
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#0000CC" />

<Button
android:id="@+id/moto_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/recognition_txt"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="onaimClick"
android:text="AIM" />

<Button
android:id="@+id/courses_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/moto_btn"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="oncoursesClick"
android:text="COURSES" />

<Button
android:id="@+id/galary_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/courses_btn"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="ongalaryClick"
android:text="GALARY" />

</RelativeLayout>

<!— activity_aim.xml 

<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#99CCFF"
android:orientation="vertical"
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="[Link]">

10
<TextView
android:id="@+id/vision_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VISION"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />

<TextView
android:id="@+id/vision_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Providing Quality Technical Education on par with Global
Standards."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/mission_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="MISSION"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textStyle="bold" />

<TextView
android:id="@+id/mission_txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="@string/mission_text1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/mission_txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="@string/mission_text2"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

11
<TextView
android:id="@+id/mission_txt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="@string/mission_text3"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

</LinearLayout>

<!—activity_courses_offered.xml 

<GridLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CC9900"
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="[Link].Courses_Offered">

<TextView
android:id="@+id/ug_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:text="@string/ugcourses"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />

<TextView
android:id="@+id/mech_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_row="1"
android:text="@string/mech"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView

12
android:id="@+id/eee_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_row="2"
android:text="@string/eee"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/ece_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_row="3"
android:text="@string/ece"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/cse_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_row="4"
android:text="@string/cse"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/civil_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_row="5"
android:text="@string/civil"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/aero_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"

13
android:layout_row="6"
android:text="@string/aero"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/it_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_row="7"
android:text="@string/it"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/pg_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginTop="10dp"
android:layout_row="8"
android:text="@string/pgcourses"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />

<TextView
android:id="@+id/ae_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_row="9"
android:text="@string/meece"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/pe_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_row="10"
android:text="@string/mepe"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

14
<TextView
android:id="@+id/mba_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_row="11"
android:text="@string/mba"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/mca_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_row="12"
android:text="@string/mca"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/mecse_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_row="13"
android:text="@string/mecse"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />

<TextView
android:id="@+id/mecad_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="5dp"
android:layout_row="14"
android:text="@string/mecad"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</GridLayout>

<!—activity_galary.xml 

15
<FrameLayout xmlns:android="[Link]
xmlns:tools="[Link]
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="[Link]">

<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="@drawable/auditorium" />

<ImageView
android:id="@+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:src="@drawable/mechblock" />

<ImageView
android:id="@+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:src="@drawable/library" />

<ImageView
android:id="@+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:src="@drawable/mbablock" />

<ImageView
android:id="@+id/imageView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:src="@drawable/mainblock" />
</FrameLayout>

// [Link]

16
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class CahcetActivity extends AppCompatActivity {

private static Button aim_btn;


private static Button courses_btn;
private static Button galary_btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_cahcet);
}

public void onaimClick(View view) {


aim_btn = (Button) findViewById([Link].moto_btn);
aim_btn.setOnClickListener(
new [Link]() {
@Override
public void onClick(View v) {
Intent intent = new Intent("[Link]");
startActivity(intent);
}
}
);
}

public void oncoursesClick(View view) {


courses_btn = (Button) findViewById([Link].courses_btn);
courses_btn.setOnClickListener(
new [Link]() {
@Override
public void onClick(View v) {
Intent intent = new
Intent("[Link].Courses_Offered");
startActivity(intent);
}
}
);
}

public void ongalaryClick(View view) {


galary_btn = (Button) findViewById([Link].galary_btn);

17
galary_btn.setOnClickListener(
new [Link]() {
@Override
public void onClick(View v) {
Intent intent = new Intent("[Link]");
startActivity(intent);
}
}
);
}
}

<!—[Link] 

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


<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".CahcetActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
<activity
android:name=".Courses_Offered"
android:label="@string/title_activity_courses__offered">
<intent-filter>
<action android:name="[Link].Courses_Offered"
/>
<category android:name="[Link]" />
</intent-filter>
</activity>
<activity
android:name=".Galary"
android:label="@string/title_activity_galary">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
<activity

18
android:name=".Aim"
android:label="@string/title_activity_aim">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>
<!—[Link] 

<resources>
<string name="app_name">CAHCET</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="title_activity_aim">Aim</string>
<string name="mission_statement">MISSION :To nurture world class
intellectual growth of our students by imparting high quality, futuristic
technical education in a cost effective [Link] inculcate love for integrity
and moral values among students to enable them to contribute to the
development of humanity through application and dissemination of technical
[Link] strive for advancement in Engineering Research and develop into a
Centre par Excellence in Engineering and Technology.</string>
<string name="vision_statement">VISION: Providing Quality Technical
Education on par with Global Standards.</string>
<string name="mission_text1">* To nurture world class intellectual growth
of our students by imparting high quality, futuristic technical education in a
cost effective manner.</string>
<string name="mission_text2">* To inculcate love for integrity and moral
values among students to enable them to contribute to the development of
humanity through application and dissemination of technical
knowledge.</string>
<string name="mission_text3">* To strive for advancement in Engineering
Research and develop into a Centre par Excellence in Engineering and
Technology.</string>
<string name="college_name">C ABDUL HAKEEM COLLEGE OF ENGINNERING AND
TECHNOLOGY</string>
<string name="title_activity_courses__offered">Courses_Offered</string>
<string name="mech">* B.E. Mechanical Engineering</string>
<string name="eee">* B.E. Electrical and Electronics Engineering</string>
<string name="ece">* B.E. Electronics and Communication
Engineering</string>
<string name="cse">* B.E. Computer Science and Engineering</string>
<string name="civil">* B.E. Civil Engineering</string>
<string name="aero">* B.E. Aeronautical Engineering</string>
<string name="it">* [Link]. Information Technology</string>
<string name="pgcourses">POST GRADUATE COURSES</string>
<string name="meece">* M.E. Applied Electronics.</string>
<string name="mepe">* M.E. Power Electronics</string>

19
<string name="mba">* MBA (Master of Business Administration)</string>
<string name="mca">* MCA (Master of Computer Application)</string>
<string name="mecse">* M.E. Computer Science and Engineering</string>
<string name="mecad">* M.E. CAD/CAM</string>
<string name="ugcourses">UNDER GRADUATE COURSES</string>
<string name="title_activity_galary">Galary</string>
</resources>

20
OUTPUT:

RESULT: Thus an android mobile application that uses Layout


Managers and Event listeners was developed and executed.

21
EXNO:03
DATE: CALCULATOR

AIM: To develop a native calculator application using android


studio mobile application development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends AppCompatActivity parent class.

Step2: Design the application with necessary widgets such as


EditText to get user inputs, TextView to display result and
Buttons to perform various arithmetic operations.

Step3: Relate the functionality of each arithmetic operator with


corresponding button.

Step4: Perform the arithmetic calculation of each operator within


the onclick method.

Step5: Display the calculation result of each operator using


TextView.

Step6: Replace the default launcher icon with new icon using
Asset Studio wizard.

Step7: Run the android application on an emulator.

22
PROGRAM

<! — activity_calc.xml 

<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
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=".CalcActivity">

<EditText
android:id="@+id/number1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:hint="0.0"
android:inputType="numberDecimal"
android:textSize="20dp" />

<EditText
android:id="@+id/number2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/number1"
android:layout_marginTop="20dp"
android:gravity="right"
android:hint="0.0"
android:inputType="numberDecimal"
android:textSize="20dp" />

<TextView

android:id="@+id/output"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/number2"
android:layout_marginTop="20dp"
android:gravity="right"
android:hint="Result"
android:textSize="20dp" />

<GridLayout
android:id="@+id/gridLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

23
android:layout_below="@id/output">

<Button
android:id="@+id/btn_plus"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp"
android:layout_row="0"
android:background="#323232"
android:onClick="onclickOperators"
android:text="+"
android:textColor="#FFFFFF"
android:textSize="32dp"
android:textStyle="bold" />

<Button
android:id="@+id/btn_minus"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp"
android:layout_row="0"
android:background="#323232"
android:onClick="onclickOperators"
android:text="-"
android:textColor="#FFFFFF"
android:textSize="32dp"
android:textStyle="bold" />

<Button
android:id="@+id/btn_ac"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp"
android:layout_row="0"
android:background="#FF8800"
android:onClick="onclickOperators"
android:text="AC"
android:textColor="#FFFFFF"
android:textSize="32dp"
android:textStyle="bold" />

24
<Button
android:id="@+id/btn_mul"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_row="1"
android:background="#323232"
android:onClick="onclickOperators"
android:text="*"
android:textColor="#FFFFFF"
android:textSize="32dp"
android:textStyle="bold" />

<Button
android:id="@+id/btn_div"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_row="1"
android:background="#323232"
android:onClick="onclickOperators"
android:text="/"
android:textColor="#FFFFFF"
android:textSize="32dp"
android:textStyle="bold" />

<Button
android:id="@+id/btn_mod"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_row="1"
android:background="#323232"
android:onClick="onclickOperators"
android:text="%"
android:textColor="#FFFFFF"
android:textSize="32dp"
android:textStyle="bold" /></GridLayout></RelativeLayout>

25
//[Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class CalcActivity extends AppCompatActivity {

EditText number1, number2;


TextView result;
double num1, num2, output;
boolean flag = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_calc);
}

public void onclickOperators(View operatorview) {


number1 = (EditText) findViewById([Link].number1);
number2 = (EditText) findViewById([Link].number2);
if ([Link]().toString().equals("") ||
[Link]().toString().equals("")) {
[Link](getBaseContext(), "Invalid Inputs",
Toast.LENGTH_LONG).show();
flag = true;
} else {
flag = false;
num1 = [Link]([Link]().toString());
num2 = [Link]([Link]().toString());
}

if ([Link]() == [Link].btn_plus && flag == false) {

output = num1 + num2;


String temp = "" + output;
result = (TextView) findViewById([Link]);
[Link](temp);

} else if ([Link]() == [Link].btn_minus && flag == false) {

26
output = num1 - num2;
String temp = "" + output;
result = (TextView) findViewById([Link]);
[Link](temp);

} else if ([Link]() == [Link].btn_mul && flag == false) {

output = num1 * num2;


String temp = "" + output;
result = (TextView) findViewById([Link]);
[Link](temp);

} else if ([Link]() == [Link].btn_div && flag == false) {

output = num1 / num2;


String temp = "" + output;
result = (TextView) findViewById([Link]);
[Link](temp);

} else if ([Link]() == [Link].btn_mod && flag == false) {

output = num1 % num2;


String temp = "" + output;
result = (TextView) findViewById([Link]);
[Link](temp);

} else if ([Link]() == [Link].btn_ac && flag == false) {


number1 = (EditText) findViewById([Link].number1);
number2 = (EditText) findViewById([Link].number2);
[Link]("");
[Link]("");
result = (TextView) findViewById([Link]);
[Link]("");
}
}
}

<!—[Link] 

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


<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"

27
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".CalcActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>

</manifest>

28
OUTPUT:

RESULT: Thus a native calculator android mobile application was


developed and executed.

29
EXNO:04
DATE: BASIC GRAPHICAL PRIMITIVES

AIM: To develop an application that draws basic graphical


primitives on the screen using android studio mobile application
development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends AppCompatActivity parent class.

Step2: Design the application with TextView widget and custom


ImageView widget which is related to a java class.

Step3: Create a java class which extends ImageView with required


constructors.

Step4: Define the overridden onTouchEvent method to handle


various motion events.

Step5: Define the overridden onDraw method to draw basic


graphical shapes.

Step6: Replace the default launcher icon with new icon using
Asset Studio wizard.

Step7: Run the android application on an emulator.

30
PROGRAM:

<!— activity_shapes.xml 

<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
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=".Shapes">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/titletext"
android:textAppearance="?android:attr/textAppearanceLarge" />

<[Link]
android:id="@+id/graphicsview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/title" />
</RelativeLayout>

//[Link]
package [Link];

import [Link];
import [Link];

public class Shapes extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_shapes);
}
}

31
//[Link]
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class GraphicalPrimitives extends ImageView {

private String shape = "";


private PointF point;
private Paint painttext = new Paint();
private Paint paintrectangle = new Paint();
private Paint paintcircle = new Paint();

public GraphicalPrimitives(Context context) {


super(context);
}

public GraphicalPrimitives(Context context, AttributeSet attrs) {


super(context, attrs);
}

public GraphicalPrimitives(Context context, AttributeSet attrs, int


defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
float x = [Link]();
float y = [Link]();
[Link]([Link]);
[Link](28);
[Link]([Link]);
[Link]([Link]);
switch ([Link]()) {
case MotionEvent.ACTION_UP:
point = new PointF(x, y);
shape = "text";
invalidate();
break;

32
case MotionEvent.ACTION_DOWN:
point = new PointF(x, y);
shape = "rectangle";
invalidate();
break;
case MotionEvent.ACTION_MOVE:
[Link](x, y);
shape = "circle";
invalidate();
break;
}
return true;
}

@Override
protected void onDraw(@NonNull Canvas canvas) {
[Link](canvas);
if ([Link]("rectangle"))
[Link](point.x, point.y, point.x * 2, point.y * 2,
paintrectangle);
else if ([Link]("text"))
[Link]("Touch Me!", point.x, point.y, painttext);
else if ([Link]("circle"))
[Link](point.x, point.y, 100, paintcircle);
}
}

<!—[Link] 

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


<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".Shapes"
android:label="@string/app_name">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity></application>
</manifest>

33
OUTPUT:

RESULT: Thus an android mobile application that draws basic


graphical primitives on the screen was developed and executed.

34
EXNO:05
DATE: DEMONSTRATION OF DATABASE

AIM: To develop an application that makes use of a database using


android studio mobile application development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends AppCompatActivity parent class.

Step2: Design the application with EditText widgets to get user


inputs and Button widgets to perform various database operations.

Step3: Define each database operation such as save, delete and


view within the corresponding onclick method of Button widget.

Step4: Create a database handler java class which extends


SQLiteOpenHelper class.

Step5: Define methods within the database handler class to


perform SQL transactions such as creating database, inserting,
deleting and retrieving rows.

Step6: Replace the default launcher icon with new icon using
Asset Studio wizard.

Step7: Run the android application on an emulator.

PROGRAM:

35
<!—activity_student_details.xml 

<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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=".Information">

<EditText
android:id="@+id/rollnumber_ET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="Roll Number"
android:inputType="number" />

<EditText
android:id="@+id/name_ET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Student&apos;s Name"
android:inputType="textPersonName" />

<EditText
android:id="@+id/course_ET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Course" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:orientation="horizontal">

<Button
android:id="@+id/savebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

36
android:background="#4CBB17"
android:onClick="onaddbtnClicked"
android:text="Save" />

<Button
android:id="@+id/deletebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#ff0000"
android:onClick="ondeletebtnClicked"
android:text="Delete" />

<Button
android:id="@+id/viewbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#0BB5FF"
android:onClick="onviewbtnClicked"
android:text="View" />

</LinearLayout>
</LinearLayout>

//[Link]
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class StudentDetails extends AppCompatActivity {


private EditText rollno, name, course;
DBHandler dbhandler;
SQLiteDatabase db;
Cursor cursor;

@Override
protected void onCreate(Bundle savedInstanceState) {

37
[Link](savedInstanceState);
setContentView([Link].activity_student_details);
dbhandler = new DBHandler(this);

rollno = (EditText) findViewById([Link].rollnumber_ET);


name = (EditText) findViewById([Link].name_ET);
course = (EditText) findViewById([Link].course_ET);
}

public void onaddbtnClicked(View view) {


int std_rollno = 0;
if ([Link]().toString().equals("") ||
[Link]().toString().equals("") ||
[Link]().toString().equals("")) {
[Link](getBaseContext(), "Invalid Inputs",
Toast.LENGTH_SHORT).show();
} else {
std_rollno = [Link]([Link]().toString());
String std_name = [Link]().toString();
String std_course = [Link]().toString();
boolean isInserted = [Link](std_rollno, std_name,
std_course);
if (isInserted)
[Link](getBaseContext(), "Details Saved",
Toast.LENGTH_SHORT).show();
else
[Link](getBaseContext(), "Saving Failed",
Toast.LENGTH_SHORT).show();
[Link]("");
[Link]("");
[Link]("");
}
}

public void ondeletebtnClicked(View view) {


if ([Link]().toString().equals("")) {
[Link](getBaseContext(), "Invalid Inputs",
Toast.LENGTH_SHORT).show();
} else {
String std_rollnumber = [Link]().toString();
Integer deleteStatus = [Link](std_rollnumber);
if (deleteStatus > 0) {
[Link](getBaseContext(), "Details Deleted",
Toast.LENGTH_SHORT).show();
} else
[Link](getBaseContext(), "Deleting Failed",
Toast.LENGTH_SHORT).show();
}
[Link]("");

38
[Link]("");
[Link]("");
}

public void onviewbtnClicked(View view) {


[Link]("");
[Link]("");
[Link]("");
String studentsinfo = "";
Cursor cursor = [Link]();
if ([Link]() == 0) {
showMessage("Error", "No Data Found!");
return;
}
while ([Link]()) {
studentsinfo += "RollNumber: " + [Link](0) + "\n";
studentsinfo += "Student Name: " + [Link](1) + "\n";
studentsinfo += "Course: " + [Link](2) + "\n";
studentsinfo += "\n";

}
showMessage("STUDENT DETAILS", studentsinfo);
}

public void showMessage(String title, String message) {


[Link] builder = new [Link](this);
[Link](true);
[Link](title);
[Link](message);
[Link]();
}
}

//[Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class DBHandler extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;


private static final String DATABASE_NAME = "students_db";
private static final String TABLE_NAME = "studentsdata";

39
private static final String COLUMN_rollno = "rollnumber";
private static final String COLUMN_name = "studentname";
private static final String COLUMN_course = "course";

public DBHandler(Context context) {


super(context, DATABASE_NAME, null, DATABASE_VERSION);
Log.e("DATABASE OPERATION", "Database Created / Opened");
}

@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_QUERY = "CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_rollno + " INTEGER PRIMARY KEY, " +
COLUMN_name + " TEXT, " +
COLUMN_course + " TEXT);";
[Link](CREATE_QUERY);
Log.e("DATABASE OPERATION", "Table Created");

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String DROP_QUERY = "DROP TABLE IF EXIST " + TABLE_NAME;
[Link](DROP_QUERY);
onCreate(db);

public boolean addStudent(int rollno, String name, String course) {


SQLiteDatabase db = [Link]();
ContentValues values = new ContentValues();
[Link](COLUMN_rollno, rollno);
[Link](COLUMN_name, name);
[Link](COLUMN_course, course);
long insertStatus = [Link](TABLE_NAME, null, values);
if (insertStatus == -1)
return false;
else
return true;
}

public Cursor displayDetails() {


String SELECT_QUERY = "SELECT * FROM " + TABLE_NAME;
SQLiteDatabase db = [Link]();
Cursor cursor = [Link](SELECT_QUERY, null);
return cursor;
}

public Integer deleteStudent(String rollno) {

40
SQLiteDatabase db = [Link]();
return [Link](TABLE_NAME, "rollnumber = ?", new String[]{rollno});
}
}

<!—[Link] 

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


<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".StudentDetails"
android:label="@string/app_name">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>

</manifest>

OUTPUT:

41
RESULT: Thus an android mobile application that makes use of a
database was developed and executed.

42
EXNO:06
DATE: RSS FEED READER

AIM: To develop an application that makes use of a RSS Feed using


android studio mobile application development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends AppCompatActivity parent class.

Step2: Design the application with TextView widgets and


ImageButton widget.

Step3: Create a RSS xml file and place it in Asset folder.

Step4: Create a new blank activity and java class which extends
AppCompatActivity parent class.

Step5: Design the new activity with ListView widget to display


each RSS feed item.

Step6: Create a java bean class with member variables, getters


and setters which matches with RSS xml file tags.

Step7: Create a SAX xml Handler class which extends


DefaultHandler class.

Step8: Define various overridden methods in SAX xml handler class


to perform extraction of content during start and end of each tag
present in RSS xml file.

Step9: Create a SAX xml parser class which instantiate parser


factory object and invoke built in parse method to perform RSS
xml file parsing.

Step10: ArrayAdapter class object is used to set the RSS feed


content into a ListView.

Step11: ListView widget is made to invoke


setonItemClickListener() method in order to open the link present
in the RSS feed tag as a new activity.

Step12: Run the android application on an emulator.

43
PROGRAM:

<!—activity_rssfeed_extract.xml 

<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
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=".RSSFeedExtract">

<TextView
android:id="@+id/welcome_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:text="Welcome!"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_blue_dark"
android:textSize="24dp" />

<TextView
android:id="@+id/message_View"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/welcome_txt"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:gravity="center_horizontal"
android:text="Read the technology tutorials RSS Feed"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageButton
android:id="@+id/rss_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/rss"
android:gravity="center_horizontal"
android:onClick="onclickReader" />

</RelativeLayout>

44
//[Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class RSSFeedExtract extends AppCompatActivity {


ImageButton rss_btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_rssfeed_extract);
}

public void onclickReader(View view) {


rss_btn = (ImageButton) findViewById([Link].rss_btn);
rss_btn.setOnClickListener(
new [Link]() {
@Override
public void onClick(View v) {
Intent intent = new
Intent("[Link]");
startActivity(intent);

}
}
);
}
}

<!—activity_rssfeed_display.xml 

<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
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="[Link]">

<ListView
android:id="@+id/rssshow"

45
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@android:color/holo_blue_bright"
android:dividerHeight="1dp"></ListView>

</RelativeLayout>

//[Link]
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class RSSFeedDisplay extends AppCompatActivity {

ListView listview;
ArrayList<RSSItems> channelvalues = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_rssfeed_display);
listview = (ListView) findViewById([Link]);
displayTag();
}

public void displayTag() {


try {
//Invoking the rssParser() with xml file as parameter
channelvalues =
[Link](getAssets().open("[Link]"));
//defining an adapter to display listview items
ArrayAdapter<RSSItems> adapter = new ArrayAdapter<RSSItems>(this,
[Link].simple_list_item_1, channelvalues);
[Link](adapter);
[Link](new
[Link]() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int
position, long id) {
// Fetching the link(website) of clicked listview item

46
Uri uri =
[Link]([Link](position).getLink());
//Opening the corresponding link (website) in a mobile
browser
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});

} catch (Exception e) {
[Link]();
}
}
}

//[Link]

package [Link];

public class RSSItems {


private String title;
private String link;
private String description;

public String getTitle() {


return title;
}

public void setTitle(String title) {


[Link] = title;
}

public String getLink() {


return link;
}

public void setLink(String link) {


[Link] = link;
}

public String getDescription() {


return description;
}

public void setDescription(String description) {


[Link] = description;
}

47
@Override
public String toString() {
String result = "" + title + "\nDescription: " + description;
return result;
}
}

//[Link]

package [Link];

import [Link];
import [Link];
import [Link];

import [Link];

public class SAXXMLHandler extends DefaultHandler {


private ArrayList<RSSItems> channels;
private String tagvalue;
private RSSItems items;

public SAXXMLHandler() {
channels = new ArrayList<RSSItems>();
}

public ArrayList<RSSItems> getChannels() {


return channels;
}

// Event Handlers
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// Reset
tagvalue = "";
if ([Link]("channel"))
// Create a new instance of RssItems Class
items = new RSSItems();
}

@Override
public void characters(char[] ch, int start, int length) throws
SAXException {
tagvalue = new String(ch, start, length);
}

48
@Override
public void endElement(String uri, String localName, String qName) throws
SAXException {
if ([Link]("channel"))
// Add it to the list
[Link](items);
else if ([Link]("title"))
[Link](tagvalue);
else if ([Link]("link"))
[Link](tagvalue);
else if ([Link]("description"))
[Link](tagvalue);
}
}

//[Link]

package [Link];

import [Link];
import [Link];

import [Link];
import [Link];

import [Link];

public class SAXXMLParser {


public static ArrayList<RSSItems> rssParser(InputStream is) {
ArrayList<RSSItems> channellist = null;
try {
// Create a XMLReader from SAXParser
XMLReader xmlReader =
[Link]().newSAXParser().getXMLReader();
// Create a SAXXMLHandler
SAXXMLHandler saxHandler = new SAXXMLHandler();
// Store handler in XMLReader
[Link](saxHandler);
// Extraction process starts
[Link](new InputSource(is));
// Get the 'Channel list'
channellist = [Link]();

} catch (Exception e) {
[Link]();
}
// return list of Channels
return channellist;

49
}
}

<!—[Link] 

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


<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<activity
android:name=".RSSFeedExtract"
android:label="@string/app_name">

<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>

</activity>

<activity
android:name=".RSSFeedDisplay"
android:label="@string/title_activity_rssfeed_display">

<intent-filter>
<action
android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>

</activity>
</application>

</manifest>

50
OUTPUT:

RESULT: Thus an android mobile application that makes use of a


RSS feed was developed and executed.

51
EXNO:07
DATE: MULTI THREADING

AIM: To develop an application that implements multi threading


using android studio mobile application development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends AppCompatActivity parent class.

Step2: Design the application with EditText, Button widgets,


ProgressBar widgets and TextView widget.

Step3: Number Series limit should be get as input from the user.

Step4: Perform the calculation of each number series in a


separate thread simultaneously.

Step5: Relate the start of each thread with the button widget.

Step6: Display the progress of each thread (number series


calculation) using ProgressBar widget.

Step7: Replace the default launcher icon with new icon using
Asset Studio wizard.

Step8: Run the android application on an emulator.

52
PROGRAM:

<!—activity_multithreading.xml 

<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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=".Multithreading">

<EditText
android:id="@+id/number_limit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:hint="Enter the Series Limit"
android:inputType="number" />

<ProgressBar
android:id="@+id/fiboprogress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp" />

<Button
android:id="@+id/fibo_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="fibonacciSeries"
android:text="Fibonacci Series" />

<TextView
android:id="@+id/fibo_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />

<ProgressBar

53
android:id="@+id/cubeprogress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp" />

<Button
android:id="@+id/cube_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="cubeSeries"
android:text="Cube Series" />

<TextView
android:id="@+id/cube_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />

<ProgressBar
android:id="@+id/squareprogress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp" />

<Button
android:id="@+id/square_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="squareSeries"
android:text="Square Series" />

<TextView
android:id="@+id/square_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />

</LinearLayout>

54
//[Link]
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class Multithreading extends AppCompatActivity {


private Button fibo, cube, square;
private ProgressBar fibobar, cubebar, squarebar;
private EditText number;
private TextView fiboresult, cuberesult, squareresult;
boolean flag = true;

int limit = 0;
String fiboseries = "0", cubeseries = "0", squareseries = "0";

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_multithreading);
fibo = (Button) findViewById([Link].fibo_btn);
fibobar = (ProgressBar) findViewById([Link]);
fiboresult = (TextView) findViewById([Link].fibo_result);

cube = (Button) findViewById([Link].cube_btn);


cubebar = (ProgressBar) findViewById([Link]);
cuberesult = (TextView) findViewById([Link].cube_result);

square = (Button) findViewById([Link].square_btn);


squarebar = (ProgressBar) findViewById([Link]);
squareresult = (TextView) findViewById([Link].square_result);

number = (EditText) findViewById([Link].number_limit);


}

Handler fibohandler = new Handler() {

@Override
public void handleMessage(Message msg) {

55
[Link]("Fibonacci Series: " + fiboseries);
fiboseries = "";
[Link](true);
}
};

Handler cubehandler = new Handler() {

@Override
public void handleMessage(Message msg) {
[Link]("Cube Series: " + cubeseries);
cubeseries = "";
}
};

Handler squarehandler = new Handler() {

@Override
public void handleMessage(Message msg) {
[Link]("Square Series: " + squareseries);
squareseries = "";
}
};

public void fibonacciSeries(View view) {

if ([Link]().toString().equals(""))
[Link](getBaseContext(), "Invalid Inputs",
Toast.LENGTH_SHORT).show();

else {
[Link]("");
[Link](false);
limit = [Link]([Link]().toString());
[Link](limit);
[Link](0);

Runnable fibotask = new Runnable() {

@Override
public void run() {
int i;
int f1, f2 = 0, f3 = 1;
for (i = 1; i <= limit; i++) {
fiboseries = fiboseries + " " + f3 + " ";
f1 = f2;
f2 = f3;
f3 = f1 + f2;
synchronized (this) {

56
try {
wait(1000);// 1 Second
[Link](i);
} catch (Exception e) {
[Link]();
}
}
}
[Link](0);
}
};
Thread fibothread = new Thread(fibotask);
[Link]();
}
}

public void cubeSeries(View view) {

if ([Link]().toString().equals(""))
[Link](getBaseContext(), "Invalid Inputs",
Toast.LENGTH_SHORT).show();

else {
[Link]("");
[Link](false);

limit = [Link]([Link]().toString());
[Link](limit);
[Link](0);

Runnable cubetask = new Runnable() {

@Override
public void run() {
int i;
int tempcube;
for (i = 1; i <= limit; i++) {
tempcube = i * i * i;
cubeseries = cubeseries + " " + tempcube + " ";
synchronized (this) {
try {
wait(500);// 1/2 Second
[Link](i);
} catch (Exception e) {
[Link]();
}
}
}
[Link](0);

57
}
};
Thread cubethread = new Thread(cubetask);
[Link]();
}
}

public void squareSeries(View view) {

if ([Link]().toString().equals(""))
[Link](getBaseContext(), "Invalid Inputs",
Toast.LENGTH_SHORT).show();

else {
[Link]("");
[Link](false);

limit = [Link]([Link]().toString());
[Link](limit);
[Link](0);

Runnable squaretask = new Runnable() {

@Override
public void run() {
int i;
int tempsquare;
for (i = 1; i <= limit; i++) {
tempsquare = i * i;
squareseries = squareseries + " " + tempsquare + " ";
synchronized (this) {
try {
wait(250);// 1/4 Second
[Link](i);
} catch (Exception e) {
[Link]();
}
}
}
[Link](0);
}
};
Thread squarethread = new Thread(squaretask);
[Link]();
}
}
}

58
<! — [Link] 

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


<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".Multithreading"
android:label="@string/app_name">
<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]" />


</intent-filter>
</activity>
</application>

</manifest>

59
OUTPUT:

RESULT: Thus an android mobile application that implements multi


threading was developed and executed.

60
EXNO:08
DATE: GPS LOCATION INFORMATION

AIM: To develop an application that uses GPS location information


using android studio mobile application development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends Activity parent class and implements
LocationListener interface.

Step2: Design the application with TextView widgets and Button


widget to display GPS location information.

Step3: Access the location system service, GPS information


provider details using the methods present in LocationManager
class.

Step4: Get the latitude and longitude coordinates from the


onLocationChanged() overridden method.

Step5: Get the provider status and other details from the
corresponding overridden methods.

Step6: Get the location updates for a particular distance and


time period within the onResume() overridden method.

Step7: Display the accessed latitude and longitude of a


particular location on a button click.

Step8: Specify the GPS access permission details in


[Link]

Step9: Replace the default launcher icon with new icon using
Asset Studio wizard.

Step10: Run the android application on an emulator and pass the


GPS location information through emulator control present in
android device monitor.

61
PROGRAM:

<!—activity_track_location.xml 

<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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=".TrackLocation">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Global Positioning System"
android:textSize="20dp" />

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="Location Information Tracker"
android:textSize="18dp" />

<Button
android:id="@+id/track_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:onClick="onclickTrack"
android:text="Get Location Coordinates" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="25dp"
android:orientation="horizontal">

<TextView
android:id="@+id/Latitude"
android:layout_width="wrap_content"

62
android:layout_height="wrap_content"
android:text="Latitude: "
android:textColor="#000000"
android:textSize="16dp" />

<TextView
android:id="@+id/Latitude_degree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unknown"
android:textColor="#000080"
android:textSize="16dp" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:id="@+id/Longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Longitude: "
android:textColor="#000000"
android:textSize="16dp" />

<TextView
android:id="@+id/Longitude_degree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unknown"
android:textColor="#000080"
android:textSize="16dp" />

</LinearLayout>
</LinearLayout>

//[Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];

63
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class TrackLocation extends Activity implements LocationListener {


private TextView latitude, latitudeField;
private TextView longitude, longitudeField;
private LocationManager locationManager;
private String provider;

@Override
public void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_track_location);
latitude = (TextView) findViewById([Link]);
longitude = (TextView) findViewById([Link]);
latitudeField = (TextView) findViewById([Link].Latitude_degree);
longitudeField = (TextView) findViewById([Link].Longitude_degree);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
Location location = null;
// Get the location manager
locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
// Define the criteria to select the locatioin provider (default)
Criteria criteria = new Criteria();
provider = [Link](criteria, false);
try {
location = [Link](provider);
} catch (Exception e) {
[Link]();
}
// Initialize the location fields
if (location != null) {
[Link]("Provider " + provider + " has been
selected.");
onLocationChanged(location);
} else {
[Link]("Location not available");
[Link]("Location not available");
}
}

public void onclickTrack(View view) {

64
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
}

// Request updates at startup


@Override
protected void onResume() {
[Link]();
try {
[Link](provider, 10, 1, this);
} catch (Exception e) {
[Link]();
}
}

// Remove the locationlistener updates when Activity is paused


@Override
protected void onPause() {
[Link]();
try {
[Link](this);
} catch (Exception e) {
[Link]();
}
}

@Override
public void onLocationChanged(Location location) {
double lat = [Link]();
double lng = [Link]();
[Link]([Link](lat));
[Link]([Link](lng));
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
[Link](this, "" + provider + "Status is: " + status,
Toast.LENGTH_SHORT).show();
}

@Override
public void onProviderEnabled(String provider) {
[Link](this, "Enabled new provider " + provider,
Toast.LENGTH_SHORT).show();
}

65
@Override
public void onProviderDisabled(String provider) {
[Link](this, "Disabled provider " + provider,
Toast.LENGTH_SHORT).show();
}
}

<!—[Link] 

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


<manifest xmlns:android="[Link]
package="[Link]" >

<uses-permission
android:name="[Link].ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission
android:name="[Link].ACCESS_FINE_LOCATION"></uses-permission>
<!-- <uses-permission
android:name="[Link].ACCESS_NETWORK_STATE"></uses-permission> -->

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".TrackLocation"
android:label="@string/app_name" >
<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]" />


</intent-filter>
</activity>
</application>

</manifest>

66
OUTPUT:

RESULT: Thus an android mobile application that uses GPS location


information was developed and executed.

67
EXNO:09
DATE: WRITING DATA TO SD CARD

AIM: To develop an application that writes data to the SD card


using android studio mobile application development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends AppCompatActivity parent class.

Step2: Design the application with EditText, Buttons and TextView


widgets.

Step3: Relate the read and write operation with the onclick
method of the Button widget.

Step4: Get the status of SD card using getExternalStorageState()


method of Environment class.

Step5: Get the path of SD card using


getExternalStorageDirectory() method of Environment class.

Step6: Write the user content into the SD card using


FileOutputStream object.

Step7: Read the content from the SD card using FileInputStream


object and BufferedReader object.

Step8: Display the content read from the SD card using TextView
widget.

Step9: Specify the external storage write and read permission


details in [Link]

Step10: Replace the default launcher icon with new icon using
Asset Studio wizard.

Step11: Run the android application on an emulator.

68
PROGRAM:

<!—activity_read_write.xml 

<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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=".ReadWrite">

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<EditText
android:id="@+id/notes_ET"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:gravity="top"
android:hint="Write Notes"
android:textColor="@android:color/primary_text_light" />

<Button
android:id="@+id/save_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="checkNotes"
android:text="Save Notes" />

<Button
android:id="@+id/read_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:onClick="readNotes"
android:text="Read Notes" />

69
<TextView
android:id="@+id/read_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_blue_dark"
android:textSize="20dp" />

</LinearLayout>
</ScrollView>
</LinearLayout>

//[Link]
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class ReadWrite extends AppCompatActivity {


EditText notes;
Button write, read;
TextView readcontent;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_read_write);
notes = (EditText) findViewById([Link].notes_ET);
write = (Button) findViewById([Link].save_btn);
read = (Button) findViewById([Link].read_btn);
readcontent = (TextView) findViewById([Link].read_txt);
}

public void checkNotes(View view) {


if ([Link]().toString().equals(""))
[Link](getApplicationContext(), "Invalid Input",

70
Toast.LENGTH_SHORT).show();
else
writeNotes();
}

public void writeNotes() {


[Link]("");
String state;
state = [Link]();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File Root = [Link]();
File Folder = new File([Link]() + "/TakeNotes");
if (![Link]()) {
[Link]();
}
File file = new File(Folder, "[Link]");
String writecontent = [Link]().toString();
try {
FileOutputStream output = new FileOutputStream(file);
[Link]([Link]());
[Link]();
[Link]("");
[Link](getApplicationContext(), "Notes Saved",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
[Link]();
}
} else
[Link](getApplicationContext(), "SD card not found",
Toast.LENGTH_SHORT).show();
}

public void readNotes(View view) {


File Root = [Link]();
File Folder = new File([Link]() + "/TakeNotes");
File file = new File(Folder, "[Link]");
String content;
try {
FileInputStream inputstream = new FileInputStream(file);
InputStreamReader inputreader = new
InputStreamReader(inputstream);
BufferedReader bufferreader = new BufferedReader(inputreader);
StringBuffer buffer = new StringBuffer();
while ((content = [Link]()) != null) {
[Link](content + "\n");
}
[Link]();
[Link]([Link]());
} catch (Exception e) {

71
[Link]();
}
}
}

<!— [Link] 

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


<manifest xmlns:android="[Link]
package="[Link]">

<uses-permission
android:name="[Link].WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission
android:name="[Link].READ_EXTERNAL_STORAGE"></uses-permission>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".ReadWrite"
android:label="@string/app_name">
<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]" />


</intent-filter>
</activity>
</application>

</manifest>

72
OUTPUT:

RESULT: Thus an android mobile application that writes data to


the SD card was developed and executed.

73
EXNO:10
DATE: MESSAGE ALERT

AIM: To develop an application that creates an alert upon


receiving a message using android studio mobile application
development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends Activity parent class and implements
OnItemClickListener.

Step2: Design the application with TextView and ListView widgets.

Step3: query() method of ContentResolver class is used to get the


sms inbox content and store it as a Cursor object.

Step4: Extract the message body and address from the cursor
object and add that information to the ArrayAdapter object.

Step5: ArrayAdapter is used along with the ListView widget to


display the messages in a list order.

Step6: OnItemClick() method is invoked after a click on ListView


widget item in order to display the received sms as a popup
(Toast).

Step7: Create a java class which extends BroadCastReceiver parent


class and define the OnReceive() method inside it.

Step8: OnReceive() method is invoked on sms arrival which


displays an alert and also updates the ArrayAdapter object with
new message.

Step9: Specify the SMS read, write and receive permission details
in [Link]

Step10: Replace the default launcher icon with new icon using
Asset Studio wizard.

Step11: Run the android application on an emulator and pass the


incoming number and message body details through emulator control
present in android device monitor.

74
PROGRAM:

<!— activity_smsnotification.xml 

<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
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=".SMSNotification">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="SMS Inbox"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ListView
android:id="@+id/SMSList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />

</LinearLayout>

//[Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

75
import [Link];

public class SMSNotification extends Activity implements OnItemClickListener {

private static SMSNotification smsobject;


ArrayList<String> smsMessagesList = new ArrayList<String>();
ListView smsListView;
ArrayAdapter arrayAdapter;

public static SMSNotification instance() {


return smsobject;
}

@Override
public void onStart() {
[Link]();
smsobject = this;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_smsnotification);
smsListView = (ListView) findViewById([Link]);
arrayAdapter = new ArrayAdapter<String>(this,
[Link].simple_list_item_1, smsMessagesList);
[Link](arrayAdapter);
[Link](this);

refreshSmsInbox();
}

public void refreshSmsInbox() {


ContentResolver contentResolver = getContentResolver();
Cursor smsInboxCursor =
[Link]([Link]("content://sms/inbox"), null, null, null,
null);
int indexBody = [Link]("body");
int indexAddress = [Link]("address");
if (indexBody < 0 || ![Link]()) return;
[Link]();
do {
String str = "SMS From: " + [Link](indexAddress)
+
"\n" + [Link](indexBody) + "\n";
[Link](str);
} while ([Link]());
}

76
public void updateList(final String smsMessage) {
[Link](smsMessage, 0);
[Link]();
}

public void onItemClick(AdapterView<?> parent, View view, int pos, long


id) {
try {
String[] smsMessages = [Link](pos).split("\n");
String address = smsMessages[0];
String smsMessage = "";
for (int i = 1; i < [Link]; ++i) {
smsMessage += smsMessages[i];
}

String smsMessageStr = address + "\n";


smsMessageStr += smsMessage;
[Link](this, smsMessageStr, Toast.LENGTH_LONG).show();
} catch (Exception e) {
[Link]();
}
}
}

//[Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class SmsBroadcastReceiver extends BroadcastReceiver {

public static final String SMS_BUNDLE = "pdus";

public void onReceive(Context context, Intent intent) {


Bundle intentExtras = [Link]();
if (intentExtras != null) {
Object[] sms = (Object[]) [Link](SMS_BUNDLE);
String smsMessageStr = "";
for (int i = 0; i < [Link]; ++i) {
SmsMessage smsMessage = [Link]((byte[])
sms[i]);

77
String smsBody = [Link]().toString();
String address = [Link]();

smsMessageStr += "SMS From: " + address + "\n";


smsMessageStr += smsBody + "\n";
}
[Link](context, smsMessageStr, Toast.LENGTH_LONG).show();

//Update the UI with message


SMSNotification smsinstance = [Link]();
[Link](smsMessageStr);
}
}
}

<!—[Link] 

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


<manifest xmlns:android="[Link]
package="[Link]">

<uses-permission android:name="[Link].WRITE_SMS" />


<uses-permission android:name="[Link].READ_SMS" />
<uses-permission android:name="[Link].RECEIVE_SMS" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".SMSNotification"
android:label="@string/app_name">
<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]" />


</intent-filter>
</activity>
<receiver
android:name=".SmsBroadcastReceiver"
android:exported="true">
<intent-filter android:priority="999">
<action android:name="[Link].SMS_RECEIVED"
/>
</intent-filter>
</receiver>
</application>

78
</manifest>
OUTPUT:

79
RESULT: Thus an android mobile application that creates an alert
upon receiving a message was developed and executed.

EXNO:11
DATE: ALARM CLOCK

AIM: To develop an alarm clock using android studio mobile


application development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends Activity parent class.

Step2: Design the application using widgets such as TextView,


ImageView and Button.

Step3: Relate the functionality of invoking the alarm with button


widget using onclick method.

Step4: Declare objects for AlarmManager, PendingIntent and


BroadcastReceiver.

Step5: Invoke the set() method of AlarmManager class to set


RTC_WAKEUP, alarm timing and pending intent.

Step6: Register the broadcast receiver object to invoke


OnReceive() overridden method on reaching the alarm time.

Step7: Display the message as an alarm alert using makeText()


method of Toast class.

Step8: Run the android application on an emulator.

80
PROGRAM:

<!—activity_alarm.xml 

<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
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=".AlarmActivity">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Alarm Demonstration"
android:textColor="@android:color/background_dark"
android:textSize="20dp" />

<ImageView
android:id="@+id/awaken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:src="@drawable/awaken" />

<Button
android:id="@+id/alarm_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/awaken"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:onClick="onClickSetAlarm"
android:text="Set Alarm" />
</RelativeLayout>

//[Link]

81
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class AlarmActivity extends Activity {

//used for register alarm manager


PendingIntent pendingIntent;
//used to store running alarm manager instance
AlarmManager alarmManager;
//Callback function for Alarm manager event
BroadcastReceiver mReceiver;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_alarm);

//Register AlarmManager Broadcast receive.


RegisterAlarmBroadcast();
}
public void onClickSetAlarm(View v)
{
//Get the current time and set alarm after 10 seconds from current
time
[Link]( AlarmManager.RTC_WAKEUP, [Link]()
+ 10000 , pendingIntent );
}
private void RegisterAlarmBroadcast()
{
Log.i("Broadcast: ", "Register Alarm Broadcast");

//This is the call back function(BroadcastReceiver) which will be


called when the
//alarm time is reached.
mReceiver = new BroadcastReceiver()
{
private static final String TAG = "Alarm Receiver";

82
@Override
public void onReceive(Context context, Intent intent)
{
Log.i(TAG,"BroadcastReceiver-OnReceive()");
[Link](context, "Alarm. Wakeup! Wakeup! Wakeup!",
Toast.LENGTH_LONG).show();
}
};

// register the alarm broadcast here


registerReceiver(mReceiver, new
IntentFilter("[Link]") );
pendingIntent = [Link]( this, 0, new
Intent("[Link]"),0 );
alarmManager = (AlarmManager)
([Link]( Context.ALARM_SERVICE ));
}
private void UnregisterAlarmBroadcast()
{
[Link](pendingIntent);
getBaseContext().unregisterReceiver(mReceiver);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// this adds items to the action bar if it is present.
getMenuInflater().inflate([Link].menu_alarm, menu);
return true;
}
@Override
protected void onDestroy() {
unregisterReceiver(mReceiver);
[Link]();
}}
//[Link]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link]">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".AlarmActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="[Link]" />

83
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>

OUTPUT:

84
RESULT: Thus an android mobile application to demonstrate alarm
clock developed and executed

EXNO:12
DATE: Date, Time Picker and Sliders.

AIM: To develop an android application to use Date, Time Picker


and Slider using android studio mobile application development
framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends Activity parent class.

Step2: Design the application using widget EditText and Buttons.

Step3: Relate the functionality of invoking the function with


button widget using onclick method.

Step4: Declare objects for Date, Time Picker and Data and Time
text.

Step5: Using Onclick() listen whether a button is pressed.

Step6: Get the time and date of the system using calendar
instances.

Step7: Display the message of current time and date using settext
function..

Step8: Run the android application on an emulator.

85
PROGRAM:

<!—activity_main.xml 

<RelativeLayout

xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/in_date"
android:layout_marginTop="82dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SELECT DATE"
android:id="@+id/btn_date"
android:layout_alignBottom="@+id/in_date"
android:layout_toRightOf="@+id/in_date"
android:layout_toEndOf="@+id/in_date" />

<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/in_time"
android:layout_below="@+id/in_date"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SELECT TIME"
android:id="@+id/btn_time"
android:layout_below="@+id/btn_date"
android:layout_alignLeft="@+id/btn_date"

86
android:layout_alignStart="@+id/btn_date" />

</RelativeLayout>

//[Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class MainActivity extends AppCompatActivity implements


[Link] {

Button btnDatePicker, btnTimePicker;


EditText txtDate, txtTime;
private int mYear, mMonth, mDay, mHour, mMinute;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

btnDatePicker=(Button)findViewById([Link].btn_date);
btnTimePicker=(Button)findViewById([Link].btn_time);
txtDate=(EditText)findViewById([Link].in_date);
txtTime=(EditText)findViewById([Link].in_time);

[Link](this);
[Link](this);

@Override
public void onClick(View v) {

if (v == btnDatePicker) {

// Get Current Date


final Calendar c = [Link]();
mYear = [Link]([Link]);
mMonth = [Link]([Link]);
mDay = [Link](Calendar.DAY_OF_MONTH);

87
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
new [Link]() {

@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth)
{

[Link](dayOfMonth + "-" + (monthOfYear +


1) + "-" + year);

}
}, mYear, mMonth, mDay);
[Link]();
}
if (v == btnTimePicker) {

// Get Current Time


final Calendar c = [Link]();
mHour = [Link](Calendar.HOUR_OF_DAY);
mMinute = [Link]([Link]);

// Launch Time Picker Dialog


TimePickerDialog timePickerDialog = new TimePickerDialog(this,
new [Link]() {

@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {

[Link](hourOfDay + ":" + minute);


}
}, mHour, mMinute, false);
[Link]();
}
}

88
OUTPUT:

RESULT: Thus an android mobile application to demonstrate using


Date, Time Picker and Sliders is developed and executed.

89
EXNO:13
DATE: Shared Preferences and fragments

AIM: To develop an android application to demonstrate Shared


Prefernces and fragments using android studio mobile application
development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends Activity parent class.

Step2: Design the application using widgets such as Button and


EditText.

Step3: Relate the functionality of invoking the respective


function for each button widget using onclick method.

Step4: Get the Email and Text and store it in a variable.

Step5: Create a variable editor using [Link]


class.

Step6: Store all the values using PutString() function using


editor object.

Step7: Run the android application on an emulator.

Step8: Create two emulator one will set the text and email and
another emulator will display the entered text when get button is
pressed.

90
PROGRAM:

<!—activity_main.xml 

<RelativeLayout xmlns:android="[Link]
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" >

<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="Save"
android:text="Save" />

<Button
android:id="@+id/btnRetr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="Get"
android:text="Retrieve" />

<Button

android:id="@+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/etEmail"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="clear"
android:text="Clear" />

<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
android:layout_below="@+id/etName"

91
android:layout_marginTop="20dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Name"
android:inputType="text"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/etEmail"
android:layout_alignStart="@+id/etEmail" />

</RelativeLayout>

//[Link]

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity {
SharedPreferences sharedpreferences;
EditText name;
EditText email;
public static final String mypreference = "mypref";
public static final String Name = "nameKey";
public static final String Email = "emailKey";

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
name = (EditText) findViewById([Link]);
email = (EditText) findViewById([Link]);
sharedpreferences = getSharedPreferences(mypreference,
Context.MODE_PRIVATE);
if ([Link](Name)) {
[Link]([Link](Name, ""));
}
if ([Link](Email)) {
[Link]([Link](Email, ""));
}
}

92
public void Save(View view) {
String n = [Link]().toString();
String e = [Link]().toString();
[Link] editor = [Link]();
[Link](Name, n);
[Link](Email, e);
[Link]();
}

public void clear(View view) {


name = (EditText) findViewById([Link]);
email = (EditText) findViewById([Link]);
[Link]("");
[Link]("");
}
public void Get(View view) {
name = (EditText) findViewById([Link]);
email = (EditText) findViewById([Link]);
sharedpreferences = getSharedPreferences(mypreference,
Context.MODE_PRIVATE);
if ([Link](Name)) {
[Link]([Link](Name, ""));
}
if ([Link](Email)) {
[Link]([Link](Email, ""));
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate([Link].menu_main, menu);
return true;
}

93
OUTPUT:

RESULT: Thus an android mobile application to demonstrate Shared


Preferences and fragements is developed and executed.

94
EXNO:14
DATE: Services and Threads.

AIM: To develop an android application to demonstrate Services


and Threads using android studio mobile application development
framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends Activity parent class.

Step2: Design the application using widgets such as TextView and


Button.

Step3: Relate the functionality of respective button with button


widget using onclick method.

Step4: Create an Intent object for both the class HelloActivity


and HelloMain and start the intent using StartService() function.

Step5: When the service is running display as Service Running


else Display Service terminated.

Step7: Run the android application on an emulator.

95
PROGRAM:

<!—activity_Hello.xml 

<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
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=".HelloActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView"
android:text="@string/service_desc"
android:layout_marginTop="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/start_service"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="@string/start_service" />
<Button
android:id="@+id/stop_Service"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/start_service"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="@string/stop_service" />
</RelativeLayout>

96
//[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class HelloActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_hello);

//starting service

findViewById([Link].start_service).setOnClickListener(new
[Link]() {

@Override
public void onClick(View v) {
Intent intent = new Intent([Link],
[Link]);
startService(intent);
}
});

//service onDestroy callback method will be called

findViewById([Link].stop_Service).setOnClickListener(new
[Link]() {

@Override
public void onClick(View v) {
Intent intent = new Intent([Link],
[Link]);
stopService(intent);
}
});
}
}

97
//[Link]

package [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class HelloService extends Service {


private static final String TAG = "HelloService";
private boolean isRunning = false;

@Override
public void onCreate() {
Log.i(TAG, "Service onCreate");
isRunning = true;

}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "Service onStartCommand");
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
try {
[Link](1000);
} catch (Exception e) {
}
if(isRunning){
Log.i(TAG, "Service running");
}
}
stopSelf();
}
}).start();
return Service.START_STICKY;
}

@Override
public IBinder onBind(Intent arg0) {
Log.i(TAG, "Service onBind");
return null;
}

@Override
public void onDestroy() {
isRunning = false;
Log.i(TAG, "Service onDestroy");

98
OUTPUT:

RESULT: Thus an android mobile application to demonstrate


Services and Threads is developed and executed.

99
EXNO:15a
DATE: Inter Process Communication

AIM: To develop an android application to demonstrate Inter


Process Communication (IPC) using android studio mobile
application development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends Activity parent class.

Step2: Design the application using widgets such as TextView.

Step3: When the application start running it displays the output


at the TextView.

Step4: Declare objects for mservies using


[Link]().

Step5: Now create another object MainObject[] as object and get


the values in the from of an array of the current given
directory.

Step6: Display the current process list under processlist()


function using append fuction.

Step7: Run the android application on an emulator.

100
PROGRAM:

<!—activity_main.xml 

<ScrollView xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">

<TextView
android:id="@+id/log"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.6"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:textSize="16sp"
tools:text="Log" />

</ScrollView>

//[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


private IMainService mService;
private TextView mLog;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
mLog = (TextView) findViewById([Link]);
Intent serviceIntent = new Intent()
.setComponent(new ComponentName(
"[Link]",
"[Link]"));
[Link]("Starting service…\n");
startService(serviceIntent);
[Link]("Binding service…\n");
bindService(serviceIntent, mConnection, BIND_AUTO_CREATE);

101
}

private ServiceConnection mConnection = new ServiceConnection() {


@Override
public void onServiceConnected(ComponentName className, IBinder
service) {
[Link]("Service binded!\n");
mService = [Link](service);
performListing();

@Override
public void onServiceDisconnected(ComponentName className) {
mService = null;
[Link]("Service disconnected.\n");
}
};

private void performListing() {


[Link]("Requesting file listing…\n");
long start = [Link]();
long end = 0;
try {
MainObject[] results = [Link]("/sdcard/testing");
end = [Link]();
int index = 0;
[Link]("Received " + [Link] + " results:\n");
for (MainObject o : results) {
if (index > 20) {
[Link]("\t -> Response truncated!\n");
break;
}
[Link]("\t -> " + [Link]() + "\n");
index++;
}
} catch (RemoteException e) {
[Link]();
}
[Link]("File listing took " + (((double) end - (double) start) /
1000d) + " seconds, or " + (end - start) + " milliseconds.\n");
try {
[Link]();
} catch (RemoteException e) {
[Link]();
}
}
}

//[Link]

package [Link];
import [Link];
import [Link];
public class MainObject implements Parcelable {
private String mPath;

102
public MainObject(Parcel source) {
mPath = [Link]();
}

public MainObject(String path) {


mPath = path;
}
public String getPath() {
return mPath;
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
[Link](mPath);
}
public static final [Link]<MainObject> CREATOR = new
[Link]<MainObject>() {
@Override
public MainObject[] newArray(int size) {
return new MainObject[size];
}
@Override
public MainObject createFromParcel(Parcel source) {
return new MainObject(source);
}
};
}

103
OUTPUT:

104
RESULT: Thus an android mobile application to demonstrate Inter
Process Communication is developed and executed.

EXNO:15b
DATE: AsyncTask

AIM: To develop an android application to demonstrate AsyncTask


using android studio mobile application development framework.

PROCEDURE:

Step1: Create a new project with blank activity and java class
which extends Activity parent class.

Step2: Design the application using widgets such as TextView.

Step3: In TestActivity class create an object for TestFragment


and initialize it with beginTransaction function.

Step4: Get the URI using HTTPGet object.

Step5: Invoke RestTask object and execute to get the activity


along with the Action for call back.

Step6: Display the Current Progress of Async Task.

Step7: Run the android application on an emulator.

105
PROGRAM:

<!—fragment_test.xml 

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

<ScrollView xmlns:android="[Link]
android:id="@+id/myScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<TextView
android:id="@+id/myTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/default_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</ScrollView>

//[Link]
package [Link];
import [Link];
import [Link];
import [Link];
public class TestActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
if (savedInstanceState == null) {
TestFragment testFragment = new TestFragment();
getFragmentManager().beginTransaction().add([Link],
testFragment).commit();
}
}
}

//[Link]
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

106
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link].twitterclient3.R;

public class TestFragment extends Fragment {


private static final String TAG = "AsyncTestFragment";

private static final String TEST_URL =


"[Link]

private static final String ACTION_FOR_INTENT_CALLBACK =


"THIS_IS_A_UNIQUE_KEY_WE_USE_TO_COMMUNICATE";

ProgressDialog progress;
private TextView ourTextView;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
return [Link]([Link].fragment_test, container, false);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
[Link](savedInstanceState);
ourTextView = (TextView)getActivity().findViewById([Link]);
getContent();
}

private void getContent() {


try {
HttpGet httpGet = new HttpGet(new URI(TEST_URL));
RestTask task = new RestTask(getActivity(),
ACTION_FOR_INTENT_CALLBACK);
[Link](httpGet);
progress = [Link](getActivity(), "Getting Data ...",
"Waiting For Results...", true);
}

catch (Exception e) {
Log.e(TAG, [Link]());

107
@Override
public void onResume() {
[Link]();
getActivity().registerReceiver(receiver, new
IntentFilter(ACTION_FOR_INTENT_CALLBACK));

@Override
public void onPause() {
[Link]();
getActivity().unregisterReceiver(receiver);

private BroadcastReceiver receiver = new BroadcastReceiver() {


@Override
public void onReceive(Context context, Intent intent) {
if (progress != null) {
[Link]();
}
String response = [Link](RestTask.HTTP_RESPONSE);
[Link](response);
Log.i(TAG, "RESPONSE = " + response);
}

};

//[Link]
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class RestTask extends AsyncTask<HttpUriRequest, Void, String>

private static final String TAG = "AsyncRestTask";


public static final String HTTP_RESPONSE = "httpResponse";

108
private Context mContext;

private HttpClient mClient;


private String mAction;

public RestTask(Context context, String action) {


mContext = context;
mAction = action;
mClient = new DefaultHttpClient();
}

public RestTask(Context context, String action, HttpClient client) {


mContext = context;
mAction = action;
mClient = client;
}

@Override

protected String doInBackground(HttpUriRequest... params) {


try {
HttpUriRequest request = params[0];
HttpResponse serverResponse = [Link](request);
BasicResponseHandler handler = new BasicResponseHandler();
return [Link](serverResponse);
}

catch (Exception e) {
[Link]();
return "";
}
}

@Override
protected void onPostExecute(String result) {
Log.i(TAG, "RESULT = " + result);
Intent intent = new Intent(mAction);
[Link](HTTP_RESPONSE, result);
[Link](intent);
}
}

109
OUTPUT:

RESULT: Thus an android mobile application to demonstrate


AsyncTask is developed and executed.

110

You might also like