0% found this document useful (0 votes)
9 views97 pages

6.MAD Lab

The document outlines the procedures for developing three different Android applications: one utilizing GUI components, fonts, and colors; another using layout managers and event listeners; and a third for a native calculator. Each application includes steps for setting up the project in Android Studio, designing the layout, and implementing functionality in Java. The final result for each application is a successful demonstration of the specified features.

Uploaded by

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

6.MAD Lab

The document outlines the procedures for developing three different Android applications: one utilizing GUI components, fonts, and colors; another using layout managers and event listeners; and a third for a native calculator. Each application includes steps for setting up the project in Android Studio, designing the layout, and implementing functionality in Java. The final result for each application is a successful demonstration of the specified features.

Uploaded by

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

Ex.

No: 1 Android Application that uses GUI components, Font

Date: and Colors

Aim:

To develop an Android Application that uses GUI components, Font and Colors.

Procedure:

Step 1: Open Android Studio Application.

Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].1″
andclick Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.

Step 4: Go to res folder and select layout. Double click the activity_main.xml file.

Step 5: Now you can see the Graphical layout window.

Step 6: Drag and drop the following components:

i. Design tab
a. One TextView with text.
b. Three Buttons with labeled as Change Font Size, Change Font Color and
Change Font Style.(or)
ii. Type the XML commands in the text tab to include the required layout
components.

Step 7: Go to package explorer in the left hand side. Select the project name.

Step 8: Go to src folder. Double click the [Link] file.

Step 9: In java file write the activities done by the application such as, actions of buttons.

Step 10: Run the android application.


Program:

Activity_main.xml:

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


<LinearLayout xmlns:android=”[Link]
android:orientation=”vertical”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<TextView
android:id=”@+id/textView”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_margin=”30dp”
android:gravity=”center”
android:text=”Hello World!”
android:textSize=”25sp”
android:textStyle=”bold” />
<Button
android:id=”@+id/button1”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_margin=”20dp”
android:gravity=”center”
android:text=”Change font size”
android:textSize=”25sp” />
<Button
android:id=”@+id/button2”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_margin=”20dp”
android:gravity=”center”
android:text=”Change color”
android:textSize=”25sp” />
</LinearLayout>

[Link]:

package [Link].exno1;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity
{
int ch=1;
float font=30;
@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
final TextView t= (TextView) findViewById([Link]);
Button b1= (Button) findViewById([Link].button1);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link](font);
font = font + 5;
if (font == 50)
font = 30;
}
});
Button b2= (Button) findViewById([Link].button2);
[Link](new [Link]() {
@Override
public void onClick(View v) {
switch (ch) {
case 1:
[Link]([Link]);
break;
case 2:
[Link]([Link]);
break;
case 3:
[Link]([Link]);
break;
case 4:
[Link]([Link]);
break;
case 5:
[Link]([Link]);
break;
case 6:
[Link]([Link]);
break;
}
ch++;
if (ch == 7)
ch = 1;
}
});
}}
Output:
Result:

Thus a Simple Android Application that uses GUI components, Font and Colors
is developed successfully.
Ex. No.:2 Android Application for Layout Managers and Event

Date: Listeners

Aim:

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

Procedure:

Step 1: Open Android Studio Application.

Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].2″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.

Step 4: Go to res folder and select layout. Double click the activity_main.xml file.

Step 5: Now you can see the Graphical layout window.

Step 6: Drag and drop the following components:

i. In Design tab include


a. Three TextViews with texts as Name, Register Number and Department.
b. Two EditText for the field Name and Register Number.
c. One Spinner to select the department of candidates.
d. f. One Button with labeled as SUBMIT(or)
ii. In Text tab, type the XML commands to include the required layout components.

Step 7: Go to package explorer in the left hand side. Select the project name.

Step 8: Go to src folder. Double click the [Link] file.

Step 9: In java file write the activities done by the application such as, actions of buttons.

Step 10: Run the android application.


Program:

Activity_main.xml:

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


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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="Details Form"
android:textSize="25sp"
android:gravity="center"/>
</LinearLayout>

<GridLayout
android:id="@+id/gridLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:layout_marginBottom="200dp"
android:columnCount="2"
android:rowCount="3">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="0"
android:layout_column="0"
android:text="Name"
android:textSize="20sp"
android:gravity="center"/>

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="0"
android:layout_column="1"
android:ems="10"/>

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="1"
android:layout_column="0"
android:text="[Link]"
android:textSize="20sp"
android:gravity="center"/>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="1"
android:layout_column="1"
android:inputType="number"
android:ems="10"/>

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="2"
android:layout_column="0"
android:text="Dept"
android:textSize="20sp"
android:gravity="center"/>

<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_row="2"
android:layout_column="1"
android:spinnerMode="dropdown"/>

</GridLayout>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginBottom="150dp"
android:text="Submit"/>

</RelativeLayout>

Activity_second.xml:

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


<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="[Link]"
android:orientation="vertical"
android:gravity="center">

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

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

</LinearLayout>

[Link]:

package [Link].exno2;

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

public class MainActivity extends AppCompatActivity {


EditText e1,e2;
Button bt;
Spinner s;

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

String name,reg,dept;

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

e1= (EditText) findViewById([Link]);


e2= (EditText) findViewById([Link].editText2);

bt= (Button) findViewById([Link]);

s= (Spinner) findViewById([Link]);

ArrayAdapter adapter= new


ArrayAdapter([Link],[Link].simple_spinner_item,dept_arra
y);
[Link](adapter);

[Link](new [Link]() {
@Override
public void onClick(View v) {

name=[Link]().toString();
reg=[Link]().toString();
dept=[Link]().toString();

Intent i = new Intent([Link],[Link]);

[Link]("name_key", name);
[Link]("reg_key",reg);
[Link]("dept_key", dept);

startActivity(i);

}
});
}
}

[Link]:

package [Link].exno2;

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

public class SecondActivity extends AppCompatActivity {

TextView t1,t2,t3;

String name,reg,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_second);

t1= (TextView) findViewById([Link].textView1);


t2= (TextView) findViewById([Link].textView2);
t3= (TextView) findViewById([Link].textView3);

Intent i = getIntent();

name=[Link]("name_key");
reg=[Link]("reg_key");
dept=[Link]("dept_key");

[Link](name);
[Link](reg);
[Link](dept);

}
}
Output:
Result:

Thus a Simple Android Application that uses Layout Managers and Event
Listeners is developed successfully.
Ex. No.:3 Simple Android Application for Native Calculator

Date:

Aim:

To develop a Simple Android Application for Native Calculator.

Procedure:

Step 1: Open Android Studio Application.

Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].3″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.

Step 4: Go to res folder and select layout. Double click the activity_main.xml file.

Step 5: Now you can see the Graphical layout window.

Step 6: Drag and drop the following components:

i. Design tab
a. One TextView with to display the result.
b. Place two EditText for getting two numbers.
c. Place four buttons ( +, -, *, / ) to perform calculations. (or)
ii. Type the XML commands in the text tab to include the required layout
components.

Step 7: Go to package explorer in the left hand side. Select the project name.

Step 8: Go to src folder. Double click the [Link] file.

Step 9: In java file write the activities done by the application such as, actions of buttons.

Step 10: Run the android application.


Program:

Activity_main.xml:

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="[Link]">
<RelativeLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">

<Button
android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/edText1"
android:layout_marginTop="60dp"
android:onClick="PressOne"
android:text="1"
android:textSize="18sp"
tools:ignore="OnClick" />

<Button
android:id="@+id/btn_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_8"
android:layout_toEndOf="@+id/btn_7"
android:layout_toRightOf="@+id/btn_7"
android:text="0"
android:textSize="18sp" />

<Button
android:id="@+id/btn_9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_6"
android:layout_toEndOf="@+id/btn_5"
android:layout_toRightOf="@+id/btn_5"
android:text="9"
android:textSize="18sp" />

<Button
android:id="@+id/btn_8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_5"
android:layout_toEndOf="@+id/btn_7"
android:layout_toRightOf="@+id/btn_7"
android:text="8"
android:textSize="18sp" />

<Button
android:id="@+id/btn_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_4"
android:layout_alignStart="@+id/btn_4"
android:layout_below="@+id/btn_4"
android:text="7"
android:textSize="18sp" />

<Button
android:id="@+id/btn_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_5"
android:layout_alignBottom="@+id/btn_5"
android:layout_toEndOf="@+id/btn_5"
android:layout_toRightOf="@+id/btn_5"
android:text="6"
android:textSize="18sp" />

<Button
android:id="@+id/btn_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_2"
android:layout_toEndOf="@+id/btn_4"
android:layout_toRightOf="@+id/btn_4"
android:text="5"
android:textSize="18sp" />

<Button
android:id="@+id/btn_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_1"
android:layout_alignStart="@+id/btn_1"
android:layout_below="@+id/btn_1"
android:text="4"
android:textSize="18sp" />

<Button
android:id="@+id/btn_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_2"
android:layout_alignBottom="@+id/btn_2"
android:layout_toEndOf="@+id/btn_2"
android:layout_toRightOf="@+id/btn_2"
android:text="3"
android:textSize="18sp" />

<Button
android:id="@+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_1"
android:layout_alignBottom="@+id/btn_1"
android:layout_toEndOf="@+id/btn_1"
android:layout_toRightOf="@+id/btn_1"
android:text="2"
android:textSize="18sp" />

<Button
android:id="@+id/btn_Add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_6"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:backgroundTint="@android:color/darker_gray"
android:text="+"
android:textColor="@android:color/background_light"
android:textSize="18sp" />

<Button
android:id="@+id/btn_Sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_Add"
android:layout_alignStart="@+id/btn_Add"
android:layout_below="@+id/btn_Add"
android:backgroundTint="@android:color/darker_gray"
android:text="-"
android:textColor="@android:color/background_light"
android:textSize="18sp" />

<Button
android:id="@+id/btn_Mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_Sub"
android:layout_alignStart="@+id/btn_Sub"
android:layout_below="@+id/btn_6"
android:backgroundTint="@android:color/darker_gray"
android:text="*"
android:textColor="@android:color/background_light"
android:textSize="18sp" />

<Button
android:id="@+id/btn_Div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_Mul"
android:layout_alignStart="@+id/btn_Mul"
android:layout_below="@+id/btn_9"
android:backgroundTint="@android:color/darker_gray"
android:text="/"
android:textColor="@android:color/background_light"
android:textSize="18sp" />

<EditText
android:id="@+id/edText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="22dp"
android:ems="10"
android:inputType="textPersonName"
android:textAlignment="textEnd"
android:textSize="24sp"
android:layout_gravity="end"
tools:ignore="RtlCompat" />

<Button
android:id="@+id/btn_calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/btn_0"
android:layout_toEndOf="@+id/btn_0"
android:backgroundTint="@android:color/holo_green_light"
android:text="="
android:textColor="@android:color/background_light"
android:textSize="18sp"
android:layout_toRightOf="@+id/btn_0"
tools:ignore="RtlCompat" />

<Button
android:id="@+id/btn_dec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_7"
android:layout_toLeftOf="@+id/btn_8"
android:layout_toStartOf="@+id/btn_8"
android:text="."
android:textSize="18sp" />
<Button
android:id="@+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/btn_Div"
android:backgroundTint="@android:color/holo_blue_dark"
android:text="clear"
android:textColor="@android:color/background_light"
android:textSize="18sp" />
</RelativeLayout>
</[Link]>

[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].R;
public class MainActivity extends AppCompatActivity {
Button btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_7, btn_8, btn_9, btn_0, btn_Add,
btn_Sub,
btn_Mul, btn_Div, btn_calc, btn_dec, btn_clear;
EditText ed1;
float Value1, Value2;
boolean mAddition, mSubtract, mMultiplication, mDivision ;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
btn_0 = (Button) findViewById([Link].btn_0);
btn_1 = (Button) findViewById([Link].btn_1);
btn_2 = (Button) findViewById([Link].btn_2);
btn_3 = (Button) findViewById([Link].btn_3);
btn_4 = (Button) findViewById([Link].btn_4);
btn_5 = (Button) findViewById([Link].btn_5);
btn_6 = (Button) findViewById([Link].btn_6);
btn_7 = (Button) findViewById([Link].btn_7);
btn_8 = (Button) findViewById([Link].btn_8);
btn_9 = (Button) findViewById([Link].btn_9);
btn_Add = (Button) findViewById([Link].btn_Add);
btn_Div = (Button) findViewById([Link].btn_Div);
btn_Sub = (Button) findViewById([Link].btn_Sub);
btn_Mul = (Button) findViewById([Link].btn_Mul);
btn_calc = (Button) findViewById([Link].btn_calc);
btn_dec = (Button) findViewById([Link].btn_dec);
btn_clear = (Button) findViewById([Link].btn_clear);
ed1 = (EditText) findViewById([Link].edText1);
btn_0.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"0");}});
btn_1.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"1");
}
});
btn_2.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"2");
}
});

btn_3.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"3");
}
});

btn_4.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"4");
}
});

btn_5.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"5");
}
});

btn_6.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"6");
}
});
btn_7.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"7");
}
});
btn_8.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"8");
}
});
btn_9.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+"9");
}
});
btn_dec.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]()+".");
}
});
btn_Add.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
if (ed1 == null){
[Link]("");
}else {
Value1 = [Link]([Link]() + "");
mAddition = true;
[Link](null);
}
}
});
btn_Sub.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
Value1 = [Link]([Link]() + "");
mSubtract = true ;
[Link](null);
}
});
btn_Mul.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
Value1 = [Link]([Link]() + "");
mMultiplication = true ;
[Link](null);
}
});
btn_Div.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
Value1 = [Link]([Link]()+"");
mDivision = true ;
[Link](null);
}
});
btn_calc.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
Value2 = [Link]([Link]() + "");
if (mAddition == true){
[Link](Value1 + Value2 +"");
mAddition=false;
}
if (mSubtract == true){
[Link](Value1 - Value2 +"");
mSubtract=false;
}
if (mMultiplication == true){
[Link](Value1 * Value2 + "");
mMultiplication=false;
}
if (mDivision == true){
[Link](Value1 / Value2+"");
mDivision=false;
}
}
});
btn_clear.setOnClickListener(new [Link]() {
@Override
public void onClick(View v) {
[Link]("");
}
});
}
}
Output:
Result:

Thus a Simple Android Application to develop a native calculator is developed


successfully.
[Link].: 4 Android Application to draw Basic Graphical Primitives

Date:

Aim:

To develop a Simple Android Application that draws basic Graphical Primitives on


the screen.

Procedure:

Step 1: Open Android Studio Application.

Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].4″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.

Step 4: Go to res folder and select layout. Double click the activity_main.xml file.

Step 5: Now you can see the Graphical layout window.

Step 6: Drag and drop the following components:

i. In Design tab include


a. One ImageView to view the shapes of graphical primitives on the
screen.(or)
ii. In Text tab, type the XML commands to include the required layout components.

Step 7: Go to package explorer in the left hand side. Select the project name.

Step 8: Go to src folder. Double click the [Link] file.

Step 9: In java file write the activities done by the application such as drawing the
graphical primitives.
Step 10: Run the android application.
Program:

Activity_main.xml:

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


<RelativeLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">

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

[Link]:

package [Link].exno4;

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

public class MainActivity extends Activity


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

Bitmap bg = [Link](720, 1280, [Link].ARGB_8888);

ImageView i = (ImageView) findViewById([Link]);


[Link](new BitmapDrawable(bg));

Canvas canvas = new Canvas(bg);

Paint paint = new Paint();


[Link]([Link]);
[Link](50);

[Link]("Rectangle", 420, 150, paint);


[Link](400, 200, 650, 700, paint);

[Link]("Circle", 120, 150, paint);


[Link](200, 350, 150, paint);

[Link]("Square", 120, 800, paint);


[Link](50, 850, 350, 1150, paint);

[Link]("Line", 480, 800, paint);


[Link](520, 850, 520, 1150, paint);
}
}
Output:
Result:

Thus a Simple Android Application that draws basic Graphical Primitives on the
screen is developed successfully.
Ex. No.: 5 Simple Android Application that makes use of Database

Date:

Aim:

To develop a Simple Android Application that makes use of Database.

Procedure:

Step 1: Open Android Studio Application.

Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].5″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.

Step 4: Go to res folder and select layout. Double click the activity_main.xml file.

Step 5: Now you can see the Graphical layout window.

Step 6: Drag and drop the following components:

i. In Design tab include


a. Place the TextView for displaying the Student Details.
b. Place three TextView for displaying "Enter Roll No","Enter Name","Enter
Mark" and create corresponding EditText for RollNo, Name,Marks.
c. Place five buttons for "INSERT","DELETE","UPDATE","VIEW" and
"VIEW ALL".(or)
ii. In Text tab, type the XML commands to include the required layout components.

Step 7: Go to package explorer in the left hand side. Select the project name.

Step 8: Go to src folder. Double click the [Link] file.

Step 9: In java file write the activities done by the application such as actions of buttons.

Step 10: Run the android application.


Program:

Activity_main.xml:

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


<AbsoluteLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="50dp"
android:layout_y="20dp"
android:text="Student Details"
android:textSize="30sp" />

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

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

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

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

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

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

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

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

</AbsoluteLayout>

[Link]:

package [Link].exno5;

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

public class MainActivity extends Activity implements OnClickListener


{
EditText Rollno,Name,Marks;
Button Insert,Delete,Update,View,ViewAll;
SQLiteDatabase db;
@Override
public void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);

Rollno=(EditText)findViewById([Link]);
Name=(EditText)findViewById([Link]);
Marks=(EditText)findViewById([Link]);
Insert=(Button)findViewById([Link]);
Delete=(Button)findViewById([Link]);
Update=(Button)findViewById([Link]);
View=(Button)findViewById([Link]);
ViewAll=(Button)findViewById([Link]);
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](this);

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


[Link]("CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,name
VARCHAR,marks VARCHAR);");
}
public void onClick(View view)
{
if(view==Insert)
{
// Checking for empty fields
if([Link]().toString().trim().length()==0||
[Link]().toString().trim().length()==0||
[Link]().toString().trim().length()==0)
{
showMessage("Error", "Please enter all values");
return;
}
[Link]("INSERT INTO student VALUES('"+[Link]()+"','"+
[Link]()+"','"+[Link]()+"');");
showMessage("Success", "Record added");
clearText();
}
if(view==Delete)
{
if([Link]().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=[Link]("SELECT * FROM student WHERE
rollno='"+[Link]()+"'", null);
if([Link]())
{
[Link]("DELETE FROM student WHERE
rollno='"+[Link]()+"'");
showMessage("Success", "Record Deleted");
}
else
{
showMessage("Error", "Invalid Rollno");
}
clearText();
}
if(view==Update)
{
if([Link]().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=[Link]("SELECT * FROM student WHERE
rollno='"+[Link]()+"'", null);
if([Link]()) {
[Link]("UPDATE student SET name='" + [Link]() + "',marks='"
+
[Link]() +"' WHERE rollno='"+[Link]()+"'");
showMessage("Success", "Record Modified");
}
else
{
showMessage("Error", "Invalid Rollno");
}
clearText();
}
if(view==View)
{
if([Link]().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=[Link]("SELECT * FROM student WHERE rollno='"+
[Link]()+"'", null);
if([Link]())
{
[Link]([Link](1));
[Link]([Link](2));
}
else
{
showMessage("Error", "Invalid Rollno");
clearText();
}
}
if(view==ViewAll)
{
Cursor c=[Link]("SELECT * FROM student", null);
if([Link]()==0)
{
showMessage("Error", "No records found");
return;
}
StringBuffer buffer=new StringBuffer();
while([Link]())
{
[Link]("Rollno: "+[Link](0)+"\n");
[Link]("Name: "+[Link](1)+"\n");
[Link]("Marks: "+[Link](2)+"\n\n");
}
showMessage("Student Details", [Link]());
}
}
public void showMessage(String title,String message)
{
Builder builder=new Builder(this);
[Link](true);
[Link](title);
[Link](message);
[Link]();
}
public void clearText()
{
[Link]("");
[Link]("");
[Link]("");
[Link]();
}
}
Output:

v
Result:

Thus a Simple Android Application that makes use of Database is


developed successfully.
Ex. No.:6 Android Application that makes use of RSS Feed

Date:

Aim:

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

Procedure:

Step 1: Open Android Studio Application.

Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].6″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.

Step 4: Go to res folder and select layout. Double click the activity_main.xml file.

Step 5: Now you can see the Graphical layout window.

Step 6: Drag and drop the following components:

i. In Design tab include


a. Place the ListView.(or)
ii. In Text tab, type the XML commands to include the required layout components.

Step 7: Go to package explorer in the left hand side. Select the project name.

Step 8: Go to src folder. Double click the [Link] file.

Step 9: In java file write the activities done by the application such as different links.

Step 10: Add <uses-permission android:name="[Link]"/>


command in [Link].
Step 11: Run the android application.
Program:
Activity_main.xml:

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


<LinearLayout xmlns:android="[Link]
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

[Link]:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link].exno6" >

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

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

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


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

</manifest>

[Link]:

package [Link].exno6;

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];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends ListActivity


{
List headlines;
List links;
@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
new MyAsyncTask().execute();
}
class MyAsyncTask extends AsyncTask<Object,Void,ArrayAdapter>
{
@Override
protected ArrayAdapter doInBackground(Object[] params)
{
headlines = new ArrayList();
links = new ArrayList();
try
{
URL url = new URL("[Link]
XmlPullParserFactory factory = [Link]();
[Link](false);
XmlPullParser xpp = [Link]();
// We will get the XML from an input stream
[Link](getInputStream(url), "UTF_8");
boolean insideItem = false;
// Returns the type of current event: START_TAG, END_TAG, etc..
int eventType = [Link]();
while (eventType != XmlPullParser.END_DOCUMENT)
{
if (eventType == XmlPullParser.START_TAG)
{
if ([Link]().equalsIgnoreCase("item"))
{
insideItem = true;
}
else if ([Link]().equalsIgnoreCase("title"))
{
if (insideItem)
[Link]([Link]()); //extract the headline
}
else if ([Link]().equalsIgnoreCase("link"))
{
if (insideItem)
[Link]([Link]()); //extract the link of article
}
}
else if(eventType==XmlPullParser.END_TAG &&
[Link]().equalsIgnoreCase("item"))
{
insideItem=false;
}
eventType = [Link](); //move to next element
}
}
catch (MalformedURLException e)
{
[Link]();
}
catch (XmlPullParserException e)
{
[Link]();
}
catch (IOException e)
{
[Link]();
}
return null;
}
protected void onPostExecute(ArrayAdapter adapter)
{
adapter = new ArrayAdapter([Link],
[Link].simple_list_item_1,
headlines);
setListAdapter(adapter);
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
Uri uri = [Link](([Link](position)).toString());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
public InputStream getInputStream(URL url)
{
try
{
return [Link]().getInputStream();
}
catch (IOException e)
{
return null;
}
}
}
Output:
Result:

Thus an Android Application that makes use of RSS Feed is developed


successfully.
Ex. No.:7 Android Application that implements Multithreading

Date:

Aim:

To develop a Android Application that implements Multithreading.

Procedure:

Step 1: Open Android Studio Application.

Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].7″
and click Next and then select the Minimum SDK and click Next -> then select the
EmptyActivity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.

Step 4: Go to res folder and select layout. Double click the activity_main.xml file.

Step 5: Now you can see the Graphical layout window.

Step 6: Drag and drop the following components:

i. In Design tab include


a. Place the ImageView to view the images on the screen.
b. Place the two buttons.(or)
ii. In Text tab, type the XML commands to include the required layout components.

Step 7: Go to package explorer in the left hand side. Select the project name.

Step 8: Go to src folder. Double click the [Link] file.

Step 9: In java file write the activities done by the application such as actions of button.

Step 10: Run the android application.


Program:

Activity_main.xml:

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


<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_margin="50dp"
android:layout_gravity="center" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_gravity="center"
android:text="Load Image 1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_gravity="center"
android:text="Load image 2" />
</LinearLayout>
[Link]:

package [Link].exno7;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity
{
ImageView img;
Button bt1,bt2;
@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
bt1 = (Button)findViewById([Link]);
bt2= (Button) findViewById([Link].button2);
img = (ImageView)findViewById([Link]);
[Link](new [Link]()
{
@Override
public void onClick(View v)
{
new Thread(new Runnable()
{
@Override
public void run()
{
[Link](new Runnable()
{
@Override
public void run()
{
[Link]([Link].india1);
}
});
}
}).start();
}
});
[Link](new [Link]()
{
@Override
public void onClick(View v)
{
new Thread(new Runnable()
{
@Override
public void run()
{
[Link](new Runnable()
{
@Override
public void run()
{
[Link]([Link].india2);
}
});
}
}).start();
}
});
}}
Output:
Result:

Thus an Android Application that implements Multithreading is developed


successfully.
Ex. No.:8 Android Application that uses GPS Location Information

Date:

Aim:

To develop an android application that uses GPS locations information.

Procedure:

Step 1: Open Android Studio Application.

Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].8″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.

Step 4: Go to res folder and select layout. Double click the activity_main.xml file.

Step 5: Now you can see the Graphical layout window.

Step 6: Drag and drop the following components:

i. In Design tab include


a. Place one button to get the Current Location.(or)
ii. In Text tab, type the XML commands to include the required layout components.

Step 7: Go to package explorer in the left hand side. Select the project name.

Step 8: Go to src folder. Double click the [Link] file.

Step 9: In java file write the activities done by the application such as finding current
location and show them to user using Toast attribute.
Step 10: Get the following permission in [Link] file:
<uses-permission android:name="[Link].ACCESS_FINE_LOCATION"/>,
<uses-permission android:name="[Link].ACCESS_COARSE_LOCATION" />

Step 11: Run the application.


Program:

Activity_main.xml:

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

<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:id="@+id/activity_main"
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]">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:layout_centerInParent="true"
android:text="GET LOCATION" />

</RelativeLayout>

[Link]:

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


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

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

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


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

[Link]

package [Link].exno8;

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 static [Link].ACCESS_COARSE_LOCATION;

import static [Link].ACCESS_FINE_LOCATION;

public class MainActivity extends AppCompatActivity {

private ArrayList<String> permissionsToRequest;

private ArrayList<String> permissionsRejected = new ArrayList<>();

private ArrayList<String> permissions = new ArrayList<>();

private final static int ALL_PERMISSIONS_RESULT = 101;

LocationTrack locationTrack;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

[Link](ACCESS_FINE_LOCATION);

[Link](ACCESS_COARSE_LOCATION);

permissionsToRequest = findUnAskedPermissions(permissions);

//get the permissions we have asked for before but are not granted..

//we will store this in a global list to access later.

if ([Link].SDK_INT >= Build.VERSION_CODES.M) {

if ([Link]() > 0)

requestPermissions([Link](new
String[[Link]()]), ALL_PERMISSIONS_RESULT);

Button btn = (Button) findViewById([Link]);

[Link](new [Link]() {

@Override

public void onClick(View view) {

locationTrack = new LocationTrack([Link]);

if ([Link]()) {

double longitude = [Link]();

double latitude = [Link]();

[Link](getApplicationContext(), "Longitude:" +
[Link](longitude) + "\nLatitude:" + [Link](latitude),
Toast.LENGTH_SHORT).show();

} else {

[Link]();

});

private ArrayList<String> findUnAskedPermissions(ArrayList<String> wanted) {

ArrayList<String> result = new ArrayList<String>();

for (String perm : wanted) {

if (!hasPermission(perm)) {
[Link](perm);

return result;

private boolean hasPermission(String permission) {

if (canMakeSmores()) {

if ([Link].SDK_INT >= Build.VERSION_CODES.M) {

return (checkSelfPermission(permission) ==
PackageManager.PERMISSION_GRANTED);

return true;

private boolean canMakeSmores() {

return ([Link].SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1);

@TargetApi(Build.VERSION_CODES.M)

@Override

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

grantResults) {

switch (requestCode) {

case ALL_PERMISSIONS_RESULT:
for (String perms : permissionsToRequest) {

if (!hasPermission(perms)) {

[Link](perms);

if ([Link]() > 0) {

if ([Link].SDK_INT >= Build.VERSION_CODES.M) {

if (shouldShowRequestPermissionRationale([Link](0)))
{

showMessageOKCancel("These permissions are mandatory for the


application.

Please allow access.",new [Link]() {

@Override

public void onClick(DialogInterface dialog, int which) {

if ([Link].SDK_INT >= Build.VERSION_CODES.M) {


requestPermissions([Link](new
String[[Link]()]), ALL_PERMISSIONS_RESULT);

});

return;

}
}

break;

private void showMessageOKCancel(String message, [Link]


okListener) {

new [Link]([Link])

.setMessage(message)

.setPositiveButton("OK", okListener)

.setNegativeButton("Cancel", null)

.create()

.show();

@Override

protected void onDestroy() {

[Link]();

[Link]();

[Link]

package [Link].exno8;

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

import [Link];

import [Link];

public class LocationTrack extends Service implements LocationListener {

private final Context mContext;

boolean checkGPS = false;

boolean checkNetwork = false;

boolean canGetLocation = false;

Location loc;

double latitude;

double longitude;

private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10;

private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1;


protected LocationManager locationManager;

public LocationTrack(Context mContext) {

[Link] = mContext;

getLocation();

private Location getLocation() {

try {

locationManager = (LocationManager) mContext


.getSystemService(LOCATION_SERVICE);

// get GPS status

checkGPS = locationManager

.isProviderEnabled(LocationManager.GPS_PROVIDER);

// get network provider status

checkNetwork = locationManager

.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

if (!checkGPS && !checkNetwork) {

[Link](mContext, "No Service Provider is available",


Toast.LENGTH_SHORT).show();

} else {

[Link] = true;

// if GPS Enabled get lat/long using GPS Services

if (checkGPS) {
if ([Link](mContext,
[Link].ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
[Link](mContext,
[Link].ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {

// TODO: Consider calling

// ActivityCompat#requestPermissions

// here to request the missing permissions, and then overriding

// public void onRequestPermissionsResult(int requestCode, String[]


// permissions, int[]
grantResults)

// to handle the case where the user grants the permission. See the
documentation

// for ActivityCompat#requestPermissions for more details.

[Link](

LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

if (locationManager != null) {

loc = locationManager

.getLastKnownLocation(LocationManager.GPS_PROVIDER);

if (loc != null) {

latitude = [Link]();
longitude = [Link]();

/*if (checkNetwork) {

if ([Link](mContext,
[Link].ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
[Link](mContext,
[Link].ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {

// TODO: Consider calling

// ActivityCompat#requestPermissions

// here to request the missing permissions, and then overriding

// public void onRequestPermissionsResult(int requestCode, String[]


// permissions, int[]
grantResults)

// to handle the case where the user grants the permission. See the
documentation

// for ActivityCompat#requestPermissions for more details.

[Link](

LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {

loc = locationManager

.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

if (loc != null) {

latitude = [Link]();

longitude = [Link]();

}*/

} catch (Exception e) {

[Link]();

return loc;

public double getLongitude() {

if (loc != null) {

longitude = [Link]();

return longitude;

}
public double getLatitude() {

if (loc != null) {

latitude = [Link]();

return latitude;

public boolean canGetLocation() {

return [Link];

public void showSettingsAlert() {

[Link] alertDialog = new [Link](mContext);

[Link]("GPS is not Enabled!");

[Link]("Do you want to turn on GPS?");

[Link]("Yes", new [Link]() {

public void onClick(DialogInterface dialog, int which) {

Intent intent = new


Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);

[Link](intent);

});

[Link]("No", new [Link]() {

public void onClick(DialogInterface dialog, int which) {


[Link]();

});

[Link]();

public void stopListener() {

if (locationManager != null) {

if ([Link](mContext,
[Link].ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
[Link](mContext,
[Link].ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {

// TODO: Consider calling

// ActivityCompat#requestPermissions

// here to request the missing permissions, and then overriding

// public void onRequestPermissionsResult(int requestCode, String[]


permissions,

// int[] grantResults)

// to handle the case where the user grants the permission. See the
documentation

// for ActivityCompat#requestPermissions for more details.

return;

[Link]([Link]);
}

@Override

public IBinder onBind(Intent intent) {

return null;

@Override

public void onLocationChanged(Location location) {

@Override

public void onStatusChanged(String s, int i, Bundle bundle) {

@Override

public void onProviderEnabled(String s) {

@Override

public void onProviderDisabled(String s) {

}
Output:
Result:

Thus an Android Application that makes GPS location information is developed


successfully.
Ex. No.: 9 Android Application that Creates an Alert Upon Receiving
Date: a Message

Aim:

To develop an Android Application that creates an alert upon receiving a message.

Procedure:

Step 1: Open Android Studio Application.

Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].9″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.

Step 4: Go to res folder and select layout. Double click the activity_main.xml file.

Step 5: Now you can see the Graphical layout window.

Step 6: This application has no components, because this just generates a notification
alone.

Step 7: Go to package explorer in the left hand side. Select the project name.

Step 8: Go to src folder. Double click the [Link] file.

Step 9: In java file write the activities done by the application such as receiving a
message and notifying it.
Step 10: Get the following permission in [Link] file:
<uses-permission android:name=”[Link].RECEIVE_SMS”/>
<uses-permission android:name=”[Link].READ_SMS”/>

Step 11: Run the application.


Program:
Activity_main.xml:

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


<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">

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

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

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

[Link]:

package [Link].exno9;

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

public class MainActivity extends AppCompatActivity


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

notify= (Button) findViewById([Link]);


e= (EditText) findViewById([Link]);

[Link](new [Link]()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent([Link], [Link]);
PendingIntent pending = [Link]([Link], 0, intent,
0);
Notification noti = new
[Link]([Link]).setContentTitle("New
Message").setContentText([Link]().toString())
.setSmallIcon([Link].ic_launcher).setContentIntent(pending).build();
NotificationManager manager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
[Link] |= Notification.FLAG_AUTO_CANCEL;
[Link](0, noti);
}
});
}
}
Output:
Result:

Thus an Android Application that creates an alert upon receiving a message is


developed successfully.
Ex. No.:10 Android Application that creates Alarm Clock

Date:

Aim:

To develop an Android Application that creates Alarm Clock.

Procedure:

Step 1: Open Android Studio Application.

Step 2: Click on File -> New -> New project -> enter the Application name as “[Link].10″
and click Next and then select the Minimum SDK and click Next -> then select the
Empty Activity and click Next and Finish.
Step 3: Go to package explorer in the left hand side. Double click on the project name.

Step 4: Go to res folder and select layout. Double click the activity_main.xml file.

Step 5: Now you can see the Graphical layout window.

Step 6: Drag and drop the following components:

i. In Design tab include


a. Place the TimePicker to set the alarm.
b. Place the ToggleButton to select the A.M or P.M.
c. Place one button labelled as On or OFF.(or)
ii. In Text tab, type the XML commands to include the required layout components.

Step 7: Go to package explorer in the left hand side. Select the project name.

Step 8: Go to src folder. Double click the [Link] file.

Step 9: In java file write the activities done by the application such as finding current
location and show them to user using Toast attribute.
Step 10: Get the following permission in [Link] file:
<uses-permission android:name=”[Link].WAKE_LOCK”/>
Step 11: Add Alarm class as a receiver in [Link] file.

Step 12: Run the android application.

Program:
Activity_main.xml:

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


<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />

<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:checked="false"
android:onClick="OnToggleClicked" />

</LinearLayout>
[Link]:

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


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

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

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


</intent-filter>
</activity>
<receiver android:name=".AlarmReceiver" >
</receiver>
</application>
</manifest>

[Link]:
package [Link].exno10;
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


{
TimePicker alarmTimePicker;
PendingIntent pendingIntent;
AlarmManager alarmManager;

@Override
protected void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
alarmTimePicker = (TimePicker) findViewById([Link]);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
}
public void OnToggleClicked(View view)
{
long time;
if (((ToggleButton) view).isChecked())
{
[Link]([Link], "ALARM ON",
Toast.LENGTH_SHORT).show();
Calendar calendar = [Link]();
[Link](Calendar.HOUR_OF_DAY, [Link]());
[Link]([Link], [Link]());
Intent intent = new Intent(this, [Link]);
pendingIntent = [Link](this, 0, intent, 0);

time=([Link]()-([Link]()%60000));
if([Link]()>time)
{
if (calendar.AM_PM == 0)
time = time + (1000*60*60*12);
else
time = time + (1000*60*60*24);
}

[Link](AlarmManager.RTC_WAKEUP, time, 10000,


pendingIntent);
}
else
{
[Link](pendingIntent);
[Link]([Link], "ALARM OFF",
Toast.LENGTH_SHORT).show();
}
}
}

[Link]:

package [Link].exno10;

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

public class AlarmReceiver extends BroadcastReceiver


{
@Override
public void onReceive(Context context, Intent intent)
{
[Link](context, "Alarm! Wake up! Wake up!",
Toast.LENGTH_LONG).show();
Uri alarmUri =
[Link](RingtoneManager.TYPE_ALARM);
if (alarmUri == null)
{
alarmUri =
[Link](RingtoneManager.TYPE_NOTIFICATION);
}
Ringtone ringtone = [Link](context, alarmUri);
[Link]();
}
}
Output:
Result:

Thus an Android Application that creates Alarm Clock is developed


successfully.

You might also like