Professional Documents
Culture Documents
0032
OBJECTIVES:
LIST OF EXPERIMENTS:
TOTAL: 45 PERIODS
OUTCOMES:
At the end of the course, the student should be able to:
Design and Implement various mobile applications using emulators.
Deploy applications to hand-held devices
To develop a Simple Android Application that uses GUI components, Font and Colors.
Procedure:
Open Android Stdio and then click on File -> New -> New project.
<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>
Now click on Design and your application will look as given below.
Output:
Result:
Thus a Simple Android Application that uses GUI components, Font and Colors is
developed and executed successfully.
Ex.No: 2 Develop an application that uses Layout Managers and event listeners.
Aim:
To develop a Simple Android Application that uses Layout Managers and Event Listeners.
Procedure:
Open Android Stdio and then click on File -> New -> New project.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">
</LinearLayout>
android:layout_column="1" android:spinnerMode="dropdown"/>
</GridLayout>
</RelativeLayout>
Now click on Design and your activity will look as given below.
So now the designing part of Main Activity is completed.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.devang.exno2.SecondActivity"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>
</LinearLayout>
Now click on Design and your activity will look as given below.
Then delete the code which is there and type the code as given below.
Code for MainActivity.java:
package com.example.exno2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
EditText e1,e2;
Button bt;
Spinner s;
String [] dept_array={"CSE","ECE","IT","Mech","Civil"};
String name,reg,dept;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s= (Spinner) findViewById(R.id.spinner);
//Creating Adapter for Spinner for adapting the data from array to Spinner
s.setAdapter(adapter);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
name=e1.getText().toString();
reg=e2.getText().toString();
dept=s.getSelectedItem().toString();
i.putExtra("name_key", name);
i.putExtra("reg_key",reg);
i.putExtra("dept_key", dept);
startActivity(i);
});
Then delete the code which is there and type the code as given below.
package com.example.exno2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
TextView t1,t2,t3;
String name,reg,dept;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent i = getIntent();
//Getting the Values from First Activity using the Intent received
name=i.getStringExtra("name_key");
reg=i.getStringExtra("reg_key");
dept=i.getStringExtra("dept_key");
t1.setText(name);
t2.setText(reg);
t3.setText(dept);
Output:
Result:
Thus a Simple Android Application that uses Layout Managers and Event Listeners is
developed and executed successfully.
Aim:
To develop a Simple Android Application for Native Calculator.
Procedure:
Creating a New project:
Open Android Stdio and then click on File -> New -> New project.
Then select the Minimum SDK as shown below and click Next.
Then select the Empty Activity and click Next.
Then delete the code which is there and type the code as given below.
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:textSize="20sp" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">
<Button
android:id="@+id/Add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+"
android:textSize="30sp"/>
<Button
android:id="@+id/Sub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-"
android:textSize="30sp"/>
<Button
android:id="@+id/Mul"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="*"
android:textSize="30sp"/>
<Button
android:id="@+id/Div"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="/"
android:textSize="30sp"/>
</LinearLayout>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Answer is"
android:textSize="30sp"
android:gravity="center"/>
</LinearLayout>
Now click on Design and your application will look as given below.
package com.example.devang.exno3;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// set a listener
Add.setOnClickListener(this);
Sub.setOnClickListener(this);
Mul.setOnClickListener(this);
Div.setOnClickListener(this);
}
@Override
public void onClick (View v)
{
float num1 = 0;
float num2 = 0;
float result = 0;
String oper = "";
// defines the button that has been clicked and performs the
corresponding operation
// write operation into oper, we will use it later for output
switch (v.getId())
{
case R.id.Add:
oper = "+";
result = num1 + num2;
break;
case R.id.Sub:
oper = "-";
result = num1 - num2;
break;
case R.id.Mul:
oper = "*";
result = num1 * num2;
break;
case R.id.Div:
oper = "/";
result = num1 / num2;
break;
default:
break;
}
// form the output line
Result.setText(num1 + " " + oper + " " + num2 + " = " + result);
}
}
Output:
Result:
Thus a Simple Android Application for Native Calculator is developed and
executed successfully.
Ex.No: 4. Write an application that draws basic graphical primitives on the screen.
Aim:
To develop a Simple Android Application that draws basic Graphical Primitives
on the screen.
Procedure:
Creating a New project:
Open Android Studio and then click on File -> New -> New project.
Then delete the code which is there and type the code as given below.
2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent">
6 <ImageView
7 android:layout_width="match_parent"
8 android:layout_height="match_parent"
9 android:id="@+id/imageView" />
10</RelativeLayout>
Now click on Design and your application will look as given below.
1 package com.example.exno4;
3 import android.app.Activity;
4 import android.graphics.Bitmap;
5 import android.graphics.Canvas;
6 import android.graphics.Color;
7 import android.graphics.Paint;
8 import android.graphics.drawable.BitmapDrawable;
9 import android.os.Bundle;
10import android.widget.ImageView;
11
12public class MainActivity extends Activity
13{
14 @Override
16 {
17 super.onCreate(savedInstanceState);
18 setContentView(R.layout.activity_main);
19
20 //Creating a Bitmap
22
25 i.setBackgroundDrawable(new BitmapDrawable(bg));
26
29
30 //Creating the Paint Object and set its color & TextSize
32 paint.setColor(Color.BLUE);
33 paint.setTextSize(50);
34
35 //To draw a Rectangle
38
42
46
50 }
51}
Output:
Result:
Thus a Simple Android Application that draws basic Graphical Primitives on
the screen is developed and executed successfully.
Aim:
To develop a Simple Android Application that makes use of Database.
Procedure:
Creating a New project:
Open Android Studio and then click on File -> New -> New project.
Then type the Application name as “ex.no.5″ and click Next.
Then select the Minimum SDK as shown below and click Next.
Then select the Empty Activity and click Next.
Then delete the code which is there and type the code as given below.
<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>
Now click on Design and your application will look as given below.
package com.example.exno5;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
Rollno=(EditText)findViewById(R.id.Rollno);
Name=(EditText)findViewById(R.id.Name);
Marks=(EditText)findViewById(R.id.Marks);
Insert=(Button)findViewById(R.id.Insert);
Delete=(Button)findViewById(R.id.Delete);
Update=(Button)findViewById(R.id.Update);
View=(Button)findViewById(R.id.View);
ViewAll=(Button)findViewById(R.id.ViewAll);
Insert.setOnClickListener(this);
Delete.setOnClickListener(this);
Update.setOnClickListener(this);
View.setOnClickListener(this);
ViewAll.setOnClickListener(this);
Output:
Result:
Thus a Simple Android Application that makes use of Database is developed
and executed successfully.
Ex.No:6. Develop an application that makes use of RSS Feed.
Aim:
To develop a Android Application that makes use of RSS Feed.
Procedure:
Creating a New project:
Open Android Studio and then click on File -> New -> New project.
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:orientation="vertical" >
7 <ListView
8 android:id="@+id/listView"
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content" />
11
12</LinearLayout>
Now click on Design and your application will look as given below.
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="com.example.exno6" >
5 <uses-permission android:name="android.permission.INTERNET"/>
7 <application
8 android:allowBackup="true"
9 android:icon="@mipmap/ic_launcher"
10 android:label="@string/app_name"
11 android:supportsRtl="true"
12 android:theme="@style/AppTheme" >
14 <intent-filter>
16
18 </intent-filter>
19 </activity>
20 </application>
21
22</manifest>
1 package com.example.exno6;
3 import android.app.ListActivity;
4 import android.content.Intent;
5 import android.net.Uri;
6 import android.os.AsyncTask;
7 import android.os.Bundle;
8 import android.view.View;
9 import android.widget.ArrayAdapter;
10 import android.widget.ListView;
11 import org.xmlpull.v1.XmlPullParser;
12 import org.xmlpull.v1.XmlPullParserException;
13 import org.xmlpull.v1.XmlPullParserFactory;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.net.MalformedURLException;
17 import java.net.URL;
18 import java.util.ArrayList;
19 import java.util.List;
20
22 {
23 List headlines;
24 List links;
25
26 @Override
28 {
29 super.onCreate(savedInstanceState);
30 new MyAsyncTask().execute();
31 }
32
34 {
35 @Override
37 {
40 try
41 {
43 XmlPullParserFactory factory =
XmlPullParserFactory.newInstance();
44
factory.setNamespaceAware(false);
45
XmlPullParser xpp = factory.newPullParser();
46
47
// We will get the XML from an input stream
48
xpp.setInput(getInputStream(url), "UTF_8");
49
boolean insideItem = false;
50
51
// Returns the type of current event: START_TAG, END_TAG,
52
etc..
53
int eventType = xpp.getEventType();
54
while (eventType != XmlPullParser.END_DOCUMENT)
55
{
56
if (eventType == XmlPullParser.START_TAG)
57
58 {
59 if (xpp.getName().equalsIgnoreCase("item"))
60 {
61 insideItem = true;
62 }
63 else if (xpp.getName().equalsIgnoreCase("title"))
64 {
65 if (insideItem)
66 headlines.add(xpp.nextText()); //extract
the headline
67
}
68
else if (xpp.getName().equalsIgnoreCase("link"))
69
{
70
if (insideItem)
71
links.add(xpp.nextText()); //extract the
72
link of article
73
}
74
}
75
else if(eventType==XmlPullParser.END_TAG &&
76 xpp.getName().equalsIgnoreCase("item"))
77 {
78 insideItem=false;
79 }
82
83 }
84 catch (MalformedURLException e)
85 {
86 e.printStackTrace();
87 }
88 catch (XmlPullParserException e)
89 {
90 e.printStackTrace();
91 }
92 catch (IOException e)
93 {
94 e.printStackTrace();
95 }
96 return null;
97 }
99 {
105
106 @Override
108 {
111 startActivity(intent);
112 }
113
115 {
116 try
117 {
119 }
return null;
}
So now the Coding part is also completed.
Now run the application to see the output.
Output:
Result:
Thus Android Application that makes use of RSS Feed is developed and
executed successfully.
Ex.9: Implement an application that writes data to the SD card.
Aim:
To develop a Android Application that writes data to the SD Card.
Procedure:
Creating a New project:
Open Android Studio and then click on File -> New -> New project.
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:layout_margin="20dp"
6 android:orientation="vertical">
8 <EditText
9 android:id="@+id/editText"
10 android:layout_width="match_parent"
11 android:layout_height="wrap_content"
12 android:singleLine="true"
13 android:textSize="30dp" />
14
15 <Button
16 android:id="@+id/button"
17 android:layout_width="match_parent"
18 android:layout_height="wrap_content"
19 android:layout_margin="10dp"
20 android:text="Write Data"
21 android:textSize="30dp" />
22
23 <Button
24 android:id="@+id/button2"
25 android:layout_width="match_parent"
26 android:layout_height="wrap_content"
27 android:layout_margin="10dp"
28 android:text="Read data"
29 android:textSize="30dp" />
30
31 <Button
32 android:id="@+id/button3"
33 android:layout_width="match_parent"
34 android:layout_height="wrap_content"
35 android:layout_margin="10dp"
36 android:text="Clear"
37 android:textSize="30dp" />
38
39</LinearLayout>
Now click on Design and your application will look as given below.
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="com.example.exno9" >
5 <uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
6
7
<application
8
android:allowBackup="true"
9
android:icon="@mipmap/ic_launcher"
10
android:label="@string/app_name"
11
android:supportsRtl="true"
12
android:theme="@style/AppTheme" >
13
<activity android:name=".MainActivity" >
14
<intent-filter>
15
<action android:name="android.intent.action.MAIN" />
16
17
<category android:name="android.intent.category.LAUNCHER" />
18
</intent-filter>
19
</activity>
20
</application>
21
</manifest>
Then delete the code which is there and type the code as given below.
1 package com.example.exno9;
3 import android.os.Bundle;
4 import android.support.v7.app.AppCompatActivity;
5 import android.view.View;
6 import android.widget.Button;
7 import android.widget.EditText;
8 import android.widget.Toast;
1 import java.io.BufferedReader;
0 import java.io.File;
1 import java.io.FileInputStream;
1
import java.io.FileOutputStream;
1
import java.io.InputStreamReader;
2
1
3 public class MainActivity extends AppCompatActivity
1{
4
EditText e1;
1
Button write,read,clear;
5
@Override
1
6 protected void onCreate(Bundle savedInstanceState)
1 {
7
super.onCreate(savedInstanceState);
1
8 setContentView(R.layout.activity_main);
1
9
e1= (EditText) findViewById(R.id.editText);
2
write= (Button) findViewById(R.id.button);
0
read= (Button) findViewById(R.id.button2);
2
1 clear= (Button) findViewById(R.id.button3);
2
2
write.setOnClickListener(new View.OnClickListener()
2
{
3
@Override
2
4 public void onClick(View v)
2 {
5
String message=e1.getText().toString();
2
try
6
{
2
7 File f=new File("/sdcard/myfile.txt");
2 f.createNewFile();
8
FileOutputStream fout=new FileOutputStream(f);
2
fout.write(message.getBytes());
9
fout.close();
3
0 Toast.makeText(getBaseContext(),"Data Written in
SDCARD",Toast.LENGTH_LONG).show();
3
1 }
3 catch (Exception e)
2
{
3
3 Toast.makeText(getBaseContext(),e.getMessage(),Toast.LEN
GTH_LONG).show();
3
4 }
3 }
5
});
3
6
read.setOnClickListener(new View.OnClickListener()
3
7 {
3
8 @Override
4 {
2
File f = new File("/sdcard/myfile.txt");
4
FileInputStream fin = new FileInputStream(f);
3
BufferedReader br = new BufferedReader(new
4
InputStreamReader(fin));
4
while ((message = br.readLine()) != null)
4
5 {
4 buf += message;
6
}
4
7 e1.setText(buf);
4 br.close();
8
fin.close();
4
Toast.makeText(getBaseContext(),"Data Recived from
9
SDCARD",Toast.LENGTH_LONG).show();
5
}
0
catch (Exception e)
5
1 {
5 Toast.makeText(getBaseContext(), e.getMessage(),
2 Toast.LENGTH_LONG).show();
5 }
3
}
5
});
4
5
5 clear.setOnClickListener(new View.OnClickListener()
5 {
6
@Override
5
public void onClick(View v)
7
{
5
8 e1.setText("");
5 }
9
});
6
0 }
6}
1
6
2
6
3
6
4
6
5
6
6
6
7
6
8
6
9
7
0
7
1
7
2
7
3
7
4
7
5
7
6
7
7
7
8
7
9
8
0
8
1
8
2
8
3
8
4
8
5
8
6
8
7
8
8
8
9
9
0
Output:
Result:
Thus Android Application that writes data to the SD Card is developed and
executed successfully.
Ex.No: 10. Implement an application that creates an alert upon receiving a message.
Aim:
To develop a Android Application that creates an alert upon receiving a message.
Procedure:
Creating a New project:
Open Android Studio and then click on File -> New -> New project.
Then type the Application name as “ex.no.10″ and click Next.
Then select the Minimum SDK as shown below and click Next.
Then select the Empty Activity and click Next.
Then delete the code which is there and type the code as given below.
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:layout_margin="10dp"
6 android:orientation="vertical">
8 <TextView
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:text="Message"
12 android:textSize="30sp" />
13
14 <EditText
15 android:id="@+id/editText"
16 android:layout_width="match_parent"
17 android:layout_height="wrap_content"
18 android:singleLine="true"
19 android:textSize="30sp" />
20
21 <Button
22 android:id="@+id/button"
23 android:layout_width="wrap_content"
24 android:layout_height="wrap_content"
25 android:layout_margin="30dp"
26 android:layout_gravity="center"
27 android:text="Notify"
28 android:textSize="30sp"/>
29
30</LinearLayout>
Now click on Design and your application will look as given below.
1 package com.example.exno10;
3 import android.app.Notification;
4 import android.app.NotificationManager;
5 import android.app.PendingIntent;
6 import android.content.Intent;
7 import android.os.Bundle;
8 import android.support.v7.app.AppCompatActivity;
9 import android.view.View;
1 import android.widget.Button;
0
import android.widget.EditText;
1
1
2 notify.setOnClickListener(new View.OnClickListener()
0
{
2
@Override
1
public void onClick(View v)
2
2 {
3 SecondActivity.class);
2 PendingIntent pending =
2 }
9
});
3
}
0
}
3
1
3
2
3
3
3
4
3
5
3
6
3
7
3
8
3
9
4
0
Output:
Result:
Thus Android Application that creates an alert upon receiving a message is
developed and executed successfully.
Aim:
To develop a Android Application that creates Alarm Clock.
Procedure:
Creating a New project:
Open Android Studio and then click on File -> New -> New project.
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical">
7 <TimePicker
8 android:id="@+id/timePicker"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:layout_gravity="center" />
12
13 <ToggleButton
14 android:id="@+id/toggleButton"
15 android:layout_width="wrap_content"
16 android:layout_height="wrap_content"
17 android:layout_gravity="center"
18 android:layout_margin="20dp"
19 android:checked="false"
20 android:onClick="OnToggleClicked" />
21
22</LinearLayout>
Now click on Design and your application will look as given below.
Now change the activity tag to receiver tag in the AndroidManifest.xml file as
shown below
3 package="com.example.exno11" >
5 <application
6 android:allowBackup="true"
7 android:icon="@mipmap/ic_launcher"
8 android:label="@string/app_name"
9 android:supportsRtl="true"
10 android:theme="@style/AppTheme" >
12 <intent-filter>
14
16 </intent-filter>
17 </activity>
19 </receiver>
20 </application>
21
22</manifest>
Then delete the code which is there and type the code as given below.
1 package com.example.exno11;
3 import android.app.AlarmManager;
4 import android.app.PendingIntent;
5 import android.content.Intent;
6 import android.os.Bundle;
7 import android.support.v7.app.AppCompatActivity;
8 import android.view.View;
9 import android.widget.TimePicker;
10import android.widget.Toast;
11import android.widget.ToggleButton;
12
13import java.util.Calendar;
14
16{
17 TimePicker alarmTimePicker;
18 PendingIntent pendingIntent;
19 AlarmManager alarmManager;
20
21 @Override
23 {
24 super.onCreate(savedInstanceState);
25 setContentView(R.layout.activity_main);
28 }
30 {
31 long time;
32 if (((ToggleButton) view).isChecked())
33 {
38
calendar.set(Calendar.MINUTE,
39alarmTimePicker.getCurrentMinute());
42
43 time=(calendar.getTimeInMillis()-
(calendar.getTimeInMillis()%60000));
44
if(System.currentTimeMillis()>time)
45
{
46
if (calendar.AM_PM == 0)
47
time = time + (1000*60*60*12);
48
else
49
time = time + (1000*60*60*24);
50
}
51
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 10000,
52
pendingIntent);
53
54 }
55 else
56 {
57 alarmManager.cancel(pendingIntent);
Then delete the code which is there and type the code as given below.
1 package com.example.exno11;
3 import android.content.BroadcastReceiver;
4 import android.content.Context;
5 import android.content.Intent;
6 import android.media.Ringtone;
7 import android.media.RingtoneManager;
8 import android.net.Uri;
9 import android.widget.Toast;
10
12{
13 @Override
15 {
25 ringtone.play();
Output:
Result:
Thus Android Application that creates Alarm Clock is developed and
executed successfully.