0% found this document useful (0 votes)
14 views89 pages

MAD Lab

The document outlines a series of experiments focused on Android application development, including installation of Android Studio and creating various applications that utilize GUI components, layout managers, and event listeners. Each experiment includes detailed steps for project creation, layout design, and Java coding to achieve specific functionalities. The document serves as a practical guide for students learning Android development through hands-on projects.

Uploaded by

roshitha1208
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)
14 views89 pages

MAD Lab

The document outlines a series of experiments focused on Android application development, including installation of Android Studio and creating various applications that utilize GUI components, layout managers, and event listeners. Each experiment includes detailed steps for project creation, layout design, and Java coding to achieve specific functionalities. The document serves as a practical guide for students learning Android development through hands-on projects.

Uploaded by

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

Date Name of the Experiment Page Marks Sign


No. No.
1. Study and installation of Andriod
Studio.
2. Develop an application that uses GUI
components, Font and Colours.
3. Develop an application that uses
Layout Managers and event listeners.
4. Write an application that draws basic
graphical primitives on the screen.
5. Develop an application that makes
use of databases .
6. Develop an application that makes
use of Notification Manager.
7. Implement an application that uses
Multi-threading.
8. Develop a native application that
uses GPS location information.
9. Implement an application that writes
data to the SD card.
10. Implement an application that
creates an alert upon receiving a
message.
11. Write a mobile application that
makes use of RSS feed.
12. Develop a mobile application to send
an email.
13. Develop a simple android application
for native calculator.

1
[Link] Study and installation of Android Studio
Date:

Aim:

To study the features and components of Android Studio.

Steps to Install Android Studio on Windows:

Step 1: Head over to [Link] to get the Android


Studio executable or zip file.

Step 2: Click on the Download Android Studio Button.

Click on the "I have read and agree with the above terms and conditions"
checkbox followed by the download button.

2
Click on the Save file button in the appeared prompt box and the file will start
downloading.

Step 3: After the downloading has finished, open the file from downloads and run
it. It will prompt the following dialog box.

Click on next. In the next prompt, it'll ask for a path for installation. Choose a path
and hit next.

Step 4: It will start the installation, and once it is completed, it will be like the
image shown below.

3
Click on next.

Step 5: Once " Finish " is clicked, it will ask whether the previous settings need to
be imported [if the android studio had been installed earlier], or not. It is better to
choose the 'Don't import Settings option'.

Click the OK button.

Step 6: This will start the Android Studio.

4
Meanwhile, it will be finding the available SDK components.

Step 7: After it has found the SDK components, it will redirect to the Welcome
dialog box.

Click on Next .

Choose Standard and click on Next. Now choose the theme, whether
the Light theme or the Dark one. The light one is called the IntelliJ theme
whereas the dark theme is called Dracula . Choose as required.

5
Click on the Next button.

Step 8: Now it is time to download the SDK components.

Click on Finish. Components begin to download let it complete.

6
The Android Studio has been successfully configured. Now it's time to launch and
build apps. Click on the Finish button to launch it.

Step 9: Click on Start a new Android Studio project to build a new app.

Result:

Thus the installation of Android Studio was successfully installed and


configured on the system.

7
Ex. No: 02 Develop an application that uses GUI components, Font and Colors
Date:

Aim:

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

Procedure:

Creating a New project:

• Open Android Studio and then click on File -> New -> New project.

• Then type the Application name as “exno2″and click Next.


• Then select the Minimum SDK as shown below and click Next
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

8
Designing layout for the Android Application:

• Click on app -> res -> layout -> activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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


<LinearLayoutxmlns: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"
9
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.

• So now the designing part is completed.

Java Coding for the Android Application:

• Click on app -> java -> [Link].exno2->MainActivity.


• Then delete the code which is there and type the code as given below.

10
Code for [Link]:

package [Link].exno2
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity :AppCompatActivity() {
var ch = 1
var font = 30f
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContentView([Link].activity_main)
val t = findViewById<TextView>([Link])
val b1 = findViewById<Button>([Link].button1)
[Link] {
[Link]= font
font += 5
if (font == 50f) font = 30f
}
val b2 = findViewById<Button>([Link].button2)
[Link] {
when (ch) {
1 ->[Link]([Link])
2 ->[Link]([Link])
3 ->[Link]([Link])
4 ->[Link]([Link])
5 ->[Link]([Link])
6 ->[Link]([Link])
}
ch++
if (ch == 7) ch = 1

11
}
}
}

• So now the Coding part is also completed.


• Now run the application to see the output.

Output:

Result:

Thus a Simple Android Application that uses Layout Managers and Event
Listeners is developed and executed successfully.

12
Ex. No. 03 Develop an application that uses Layout Managers and Event Listeners
Date:

Aim:

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

Procedure:

Creating a New project:

• Open Android Studio and then click on File -> New -> New project.

• Then type the Application name as “exno3″ and click Next.


• Then select the Minimum SDK as shown below and click Next.
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

Creating Second Activity for the Android Application:

• Click on File -> New -> Activity -> Empty Activity

13
• Type the Activity Name asSecondActivity and click Finish button.
• Thus Second Activity For the application is created.

Designing Layout for Main Activity:

• Click on app -> res -> layout -> activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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


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

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"

14
android:ems="10"
android:inputType="textPersonName"
android:hint="Name" />

<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="textPersonName"
android:hint="Registration Number" />

<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_marginTop="20dp"/>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/spinner"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Submit" />
</RelativeLayout>

15
Designing Layout for Second Activity:

• Click on app -> res -> layout -> activity_second.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_second.xml:

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


<LinearLayoutxmlns: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"

16
android:layout_margin="20dp"
android:text="New Text"
android:textSize="30sp"/>
</LinearLayout>

• Now click on Design and your activity will look as given below.
• So now the designing part of Second Activity is also completed.

Java Coding for the Android Application:

• Java Coidng for Main Activity:


• Click on app -> java -> [Link].exno3 ->MainActivity.
• Then delete the code which is there and type the code as given below.

Code for [Link]:

package [Link].exno3;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
//Defining the Views
EditText e1,e2;
Button bt;
Spinner s;
//Data for populating in Spinner
String [] dept_array={"CSE","ECE","IT","Mech","Civil"};
String name,reg,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {

17
[Link](savedInstanceState);
setContentView([Link].activity_main);
//Referring the Views
e1= (EditText) findViewById([Link]);
e2= (EditText) findViewById([Link].editText2);
bt= (Button) findViewById([Link]);
s= (Spinner) findViewById([Link]);
//Creating Adapter for Spinner for adapting the data from array to Spinner
ArrayAdapter adapter= new

ArrayAdapter([Link],[Link].simple_spinner_item,dept_array)
;
[Link](adapter);
//Creating Listener for Button
[Link](new [Link]() {
@Override
public void onClick(View v) {
//Getting the Values from Views(Edittext& Spinner)
name=[Link]().toString();
reg=[Link]().toString();
dept=[Link]().toString();
//Intent For Navigating to Second Activity
Intent i = new Intent([Link],[Link]);
//For Passing the Values to Second Activity
[Link]("name_key", name);
[Link]("reg_key",reg);
[Link]("dept_key", dept);
startActivity(i);
}
});
}
}

18
Java Coding for Second Activity:

• Click on app -> java -> [Link].exno3 ->SecondActivity.


• Then delete the code which is there and type the code as given below

Code for [Link]:

package [Link].exno3;
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);

//Getting the Intent


Intenti = getIntent();

//Getting the Values from First Activity using the Intent received
name=[Link]("name_key");
reg=[Link]("reg_key");
dept=[Link]("dept_key");

19
//Setting the Values to Intent
[Link](name);
[Link](reg);
[Link](dept);
}
}

• So now the Coding part of Second Activity is also completed.


• Now run the application to see the output.

Output:

Result:

Thus a Simple Android Application that uses Layout Managers and Event
Listeners is developed and executed successfully.

20
Ex No. 04 Write an application that draws Basic Graphical Primitives on the
Date: 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 type the Application name as “exno4″ and click Next.
• Then select the Minimum SDK as shown below and click Next.
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

Designing layout for the Android Application:

• Click on app -> res -> layout -> activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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


<RelativeLayoutxmlns:android="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"

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

• Now click on Design and your application will look as given below.
• So now the designing part is completed.

Java Coding for the Android Application:

• Click on app -> java -> [Link].exno4 ->MainActivity.


• Then delete the code which is there and type the code as given below.

Code for [Link]:

package [Link].exno4
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
class MainActivity :AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContentView([Link].activity_main)
valbg = [Link](720, 1280, [Link].ARGB_8888)
vali = findViewById<ImageView>([Link])
[Link]= BitmapDrawable(resources, bg)
val canvas = Canvas(bg)
val paint = Paint()
[Link]= [Link]
[Link]= 50f
[Link]("Rectangle", 420f, 150f, paint)

22
[Link](400f, 200f, 650f, 700f, paint)
[Link]("Circle", 120f, 150f, paint)
[Link](200f, 350f, 150f, paint)
[Link]("Square", 120f, 800f, paint)
[Link](50f, 850f, 350f, 1150f, paint)
[Link]("Line", 480f, 800f, paint)
[Link](520f, 850f, 520f, 1150f, paint) }
}

Output:

Result:

Thus a Simple Android Application that draws basic Graphical Primitives on


the screen is developed and executed successfully.

23
Ex. No.05
Develop an application that makes use of database
Date:

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 “exno5″ and click Next.
• Then select the Minimum SDK as shown below and click Next.
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

Designing layout for the Android Application:

• Click on app -> res -> layout -> activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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


<AbsoluteLayoutxmlns: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"

24
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" />
25
<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"
26
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.
• So now the designing part is completed.

Java Coding for the Android Application:

• Click on app -> java -> [Link].exno5->MainActivity.


• Then delete the code which is there and type the code as given below.

27
Code for [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
{
EditTextRollno,Name,Marks;
Button Insert,Delete,Update,View,ViewAll;
SQLiteDatabasedb;
/** Called when the activity is first created. */
@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);

28
[Link](this);
[Link](this);
[Link](this);
[Link](this);
// Creating database and table
db=openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
[Link]("CREATE TABLE IF NOT EXISTS
student(rollnoVARCHAR,nameVARCHAR,marks VARCHAR)");
}
public void onClick(View view)
{
// Inserting a record to the Student table
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();
}
// Deleting a record from the Student table
if(view==Delete)
{
// Checking for empty roll number
if([Link]().toString().trim().length()==0)
29
{
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","InvalidRollno");
}
clearText();
}
// Updating a record in the Student table
if(view==Update)
{
// Checking for empty roll number
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");
30
}
else {
showMessage("Error","InvalidRollno");
}
clearText();
}
// Display a record from the Student table
if(view==View)
{
// Checking for empty roll number
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();
}
}
// Displaying all the records
if(view==ViewAll)
{
Cursor c=[Link]("SELECT * FROM student", null);
if([Link]()==0)
31
{
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](); }
}

• So now the Coding part is also completed.


• Now run the application to see the output.

32
Output:

33
Result:

Thus a Simple Android Application that makes use of Database is developed


and executed successfully.
34
Ex. No. 06 Develop an application that makes use of Notification Manager
Date:

Aim:

To develop an Android Application that makes use of Notification Manager.

Procedure:

Creating a New project:

• Open Android Studio and then click on File -> New -> New project.
• Then type the Application name as “exno6″and click Next.
• Then select the Minimum SDK as shown below and click Next.
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

Designing layout for the Android Application:

• Click on app -> res -> layout - > activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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


<LinearLayoutxmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
35
<Button
android:id="@+id/btnSimpleNotification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simple Notification" />
<Button
android:id="@+id/btnNotificationIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification With Icon"/>
<Button
android:id="@+id/btnNotificationImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification With Image"/>
<Button
android:id="@+id/btnNotificationWithGroupConvo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification With Group Conversation"/>
<Button
android:id="@+id/btnNotificationSemantic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification Semantic Action"/>
</LinearLayout>

Java Coding forthe Android Application:

• Click on app -> java -> [Link].exno6 ->MainActivity.


• Then delete the code which is there and type the code as given below.

36
Code for [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]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : AppCompatActivity(), [Link] {


private lateinit var notificationManager: NotificationManager
private lateinit var builder: [Link]
private var charSequence: CharSequence = ""
private valrequestPermissionLauncher = registerForActivityResult(
[Link]()
) { isGranted: Boolean ->
if (isGranted) {

37
// Permission is granted. Continue the action or workflow in your
// app.
} else {
// Explain to the user that the feature is unavailable because the
// features requires a permission that the user has denied. At the
// same time, respect the user's decision. Don't link to system
// settings in an effort to convince the user to change their
// decision.
}
}
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContentView([Link].activity_main)
valbtnSimpleNotification: Button = findViewById([Link])
valbtnNotificationIcon: Button = findViewById([Link])
valbtnNotificationImage: Button = findViewById([Link])
valbtnNotificationWithGroupConvo: Button =
findViewById([Link])
valbtnNotificationSemantic: Button = findViewById([Link])
charSequence = [Link]
[Link](this)
[Link](this)
[Link](this)
[Link](this)
[Link](this)
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as
NotificationManager
if ([Link].SDK_INT>= Build.VERSION_CODES.O) {
val name: CharSequence = "My Notification"

valdescription = "yadda yadda"


val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel("1", name, importance)

38
[Link]= description
[Link](channel)
builder = [Link](this@MainActivity, [Link])
.setSmallIcon([Link].ic_launcher)
} else {
builder = [Link](this@MainActivity, "1")
.setSmallIcon([Link].ic_launcher)
}
}
override fun onClick(v: View?) {
when (v?.id) {
[Link]->simpleNotification()
[Link]->notificationWithIcon()
[Link]->notificationWithImage()
[Link]->notificationWithGroupConvo()
[Link]->notificationSemantic()
}
}
private fun simpleNotification() {
valjd = [Link]().setName("JournalDev ").setImportant(true).build()
val style = [Link](jd)
.addMessage("Check me out", Date().time, jd)
[Link](style)
askForNotificationPermission()
[Link](1, [Link]())
}
private fun notificationWithIcon() {
valanupam = [Link]()
.setName("Anupam")
.setIcon([Link](this,
[Link].ic_launcher_background))
.setImportant(true).build()
val style = [Link](anupam)
39
.addMessage("Check out my latest article!", Date().time, anupam)
[Link](style)
askForNotificationPermission()
[Link](2, [Link]())
}
private fun notificationWithImage() {
val bot = [Link]()
.setName("Bot")
.setBot(true)
.setImportant(true)
.build()
valuri = [Link]("[Link]://[Link].exno5/drawable/" +
[Link].ic_launcher_background)
val message = [Link]("Check out my latest
article!", Date().time, bot)
[Link]("image/*", uri)
val style = [Link](bot)
.addMessage(message)
.setGroupConversation(true)
[Link](style)
askForNotificationPermission()
[Link](3, [Link]())
}
private fun notificationWithGroupConvo() {
valjd = [Link]()
.setName("JournalDev").build()
valanupam = [Link]()
.setName("Anupam")
.setIcon([Link](this,
[Link].ic_launcher_foreground))
.setImportant(true).build()
val bot = [Link]()
.setName("Bot").setBot(true).build()
40
valuri = [Link]("[Link]://[Link].exno5/drawable/" +
[Link].ic_launcher_background)
val message = [Link]("", Date().time, bot)
[Link]("image/*", uri)
val style = [Link](bot)
.addMessage("Hi. How are you?", Date().time, anupam)
.addMessage(message)
.addMessage("Does this image look good?", Date().time, bot)
.addMessage("Looks good!", Date().time, jd)
.setGroupConversation(true)
.setConversationTitle("Sample Conversation")
[Link](style)
askForNotificationPermission()
[Link](4, [Link]())
}
private fun notificationSemantic() {
valjd = [Link]()
.setName("JournalDev")
.build()
valanupam = [Link]()
.setName("Anupam")
.setIcon([Link](this,
[Link].ic_launcher_background))
.setImportant(true)
.build()
val bot = [Link]()
.setName("Bot")
.setBot(true)
.build()
valuri = [Link]("[Link]://[Link].exno5/drawable/" +
[Link].ic_launcher_background)
val intent = Intent(this, MainActivity::[Link])
[Link]("hi", "Notifications were read")
41
valpendingIntent = [Link](this, 0, intent,
PendingIntent.FLAG_IMMUTABLE)
val message = [Link]("", Date().time, bot)
[Link]("image/*", uri)
valreplyAction =
[Link](
[Link].ic_launcher_background, "MARK READ", pendingIntent
)
.setSemanticAction([Link].SEMANTIC_ACTION_MARK_AS_RE
AD)

.build()
valseparateBuilder = [Link](this, "1")
.setSmallIcon([Link].ic_launcher)
.addAction(replyAction)
val style = [Link](bot)
.addMessage("Hi. How are you?", Date().time, anupam)
.addMessage(message)
.addMessage("Does this image look good?", Date().time, bot)
.addMessage("Looks good!", Date().time, jd)
.setGroupConversation(true)
.setConversationTitle("Sample Conversation")
[Link](style)
askForNotificationPermission()
[Link](5,[Link]())
}
override fun onResume() {
[Link]()
if (intent?.extras!= null) {
val value = [Link]("hi")

[Link](applicationContext, value, Toast.LENGTH_LONG).show()


}
}
42
private fun askForNotificationPermission() {
if ([Link].SDK_INT>= Build.VERSION_CODES.TIRAMISU) {
if ([Link](this,
[Link].POST_NOTIFICATIONS) ==
PackageManager.PERMISSION_GRANTED
){
// FCM SDK (and your app) can post notifications.
} else if
(shouldShowRequestPermissionRationale([Link].POST_NOTIFICATI
ONS)) {
// TODO: display an educational UI explaining to the user the features
that will be enabled
// by granting the POST_NOTIFICATION permission. This UI should provide the
user
// with two choices: \"Grants\" and \"No thanks\". If the user selects
\"Grants\", invoke
// the requestPermissionLauncher. Else, if the user selects \"No thanks\", allow
// the user to continue without notifications.
}

else {
// Directly ask for the permission

[Link]([Link].POST_NOTIFICATIONS)
}
}
}
}

43
Output:

Result:

Thus Android Application that makes use of notification manager is


developed and executed successfully.

44
Ex. No. 07 Implement an application that uses Multi-threading
Date:

Aim:

To develop an Android Application that implements Multi threading.

Procedure:

Creating a New project:

• Open Android Studio and then click on File -> New -> New project.
• Then type the Application name as “exno7″and click Next.
• Then select the Minimum SDK as shown below and click Next.
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

Designing layout for the Android Application:

• Click on app -> res -> layout -> activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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


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

<ImageView
android:id="@+id/imageView"
android:layout_width="250dp"
45
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>

• Now click on Design and your application will look as given below.
• So now the designing part is completed.

Java Coding for the Android Application:

• Click on app -> java -> [Link].exno7 ->MainActivity.


• Then delete the code which is there and type the code as given below.

Code for [Link]:

package [Link].exno7;
import [Link]
import [Link]
import [Link]

46
import [Link]
import [Link]
import [Link]

class MainActivity :AppCompatActivity() {


private lateinit var imageView: ImageView
private lateinit var button: Button
private lateinit var button2: Button

override fun onCreate(savedInstanceState: Bundle?) {


[Link](savedInstanceState)
setContentView([Link].activity_main)

imageView = findViewById([Link])
button = findViewById([Link])
button2 = findViewById([Link].button2)

[Link] {
Thread {
try {
valurl = URL("[Link]
7236918_1280.jpg")
val bitmap =
[Link]([Link]().getInputStream())
[Link] {
[Link](bitmap)
}
} catch (e: Exception) {
[Link]()
}
}.start()
}

47
[Link] {
Thread {
try {
valurl = URL("[Link]
map-template_762986-[Link]?semt=ais_rp_50_assets&w=740&q=80")
val bitmap =
[Link]([Link]().getInputStream())
[Link] {
[Link](bitmap)
}
} catch (e: Exception) {
[Link]()
}
}.start()
}
}
}

• So now the Coding part is also completed.


• Now run the application to see the output.

Note:

• Before running the application, copy the images given below and paste it in
“app -> res -> drawable” by pressing “right click mouse button on
drawable” and selecting the “Paste” option.

48
Output:

Result:

Thus Android Application that implements Multi threading is developed


and executed successfully.

49
Ex. No. 08 Develop a native application that uses GPS location information
Date:

Aim:

To develop an Android Application that uses GPS location information.

Procedure:

Creating a New project:

• Open Android Studio and then click on File -> New -> New project.
• Then type the Application name as “exno8″and click Next.
• Then select the Minimum SDK as shown below and click Next.
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

Designing layout for the Android Application:

• Click on app -> res -> layout -> activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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


<LinearLayoutxmlns:android = "[Link]
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:orientation = "vertical" >
<Button
android:id = "@+id/button"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"

50
android:text = "getlocation"/>
</LinearLayout>

• Now click on Design and your application will look as given below.
• So now the designing part is completed.

Following will be the content of res/values/[Link] to define two new


constants –
<?xml version = "1.0" encoding = "utf-8"?>
<resources>
<string name = "app_name">Tutorialspoint</string>
</resources>

Adding permissions in Manifest for the Android Application:

• Click on app -> manifests -> [Link].

Code for [Link]:

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


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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Exno7">
<activity
android:name=".MainActivity"
51
android:exported="true">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>

Java Coding for the Android Application:

• Click on app -> java -> [Link].exno8->MainActivity.


• Then delete the code which is there and type the code as given below.

Code for [Link]:

package [Link].exno8;
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : AppCompatActivity() {


private lateinit var btnShowLocation: Button
private val REQUEST_CODE_PERMISSION = 2
private valmPermission = [Link].ACCESS_FINE_LOCATION
private var gps: GPSTracker? = null
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContentView([Link].activity_main)

52
try {
if ([Link](this, mPermission) !=
PackageManager.PERMISSION_GRANTED) {
[Link](this, arrayOf(mPermission),
REQUEST_CODE_PERMISSION)
}
} catch (e: Exception) {
[Link]()
}

btnShowLocation = findViewById([Link])

[Link] {
gps = GPSTracker(this@MainActivity)
if (gps!!.canGetLocation()) {
val latitude = gps!!.getLatitude()
val longitude = gps!!.getLongitude()
[Link](
applicationContext,
"Your Location is - \nLat: $latitude\nLong: $longitude",
Toast.LENGTH_LONG
).show()
} else {
gps!!.showSettingsAlert()
}
}
}
override fun onDestroy() {
[Link]()
gps?.stopUsingGPS() }
}

• Following is the content of the modified main activity file [Link].

53
Code for [Link]:

package [Link].exno7;
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 GPSTracker extends Service implements LocationListener {


private final Context mContext;
private booleancanGetLocation = false;
private Location location;
private double latitude;
private double longitude;
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10
meters
private static final long MIN_TIME_BW_UPDATES = 1000 * 60; // 1 minute
protected LocationManagerlocationManager;
public GPSTracker(Context context) {
[Link] = context;
getLocation();
}

@SuppressLint("MissingPermission")

54
public void getLocation() {
try {
locationManager = (LocationManager)
[Link](LOCATION_SERVICE);
if (locationManager != null) {
// getting GPS status
booleanisGPSEnabled =
[Link](LocationManager.GPS_PROVIDER);
// getting network status
booleanisNetworkEnabled =
[Link](LocationManager.NETWORK_PROVIDER);

if (isGPSEnabled || isNetworkEnabled) {
[Link] = true;
// First get location from Network Provider
if (isNetworkEnabled) {
[Link](
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
location =
[Link](LocationManager.NETWORK_PROVIDER)
;
if (location != null) {
latitude = [Link]();
longitude = [Link]();
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled&& location == null) {
[Link](
LocationManager.GPS_PROVIDER,
55
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
location =
[Link](LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = [Link]();
longitude = [Link]();
}
}
}
}
} catch (Exception e) {
Log.e("GPSTracker", "Error getting location", e);
}
}

public void stopUsingGPS() {


if (locationManager != null) {
[Link](this);
}
}

public double getLatitude() {


if (location != null) {
latitude = [Link]();
}
return latitude;
}

public double getLongitude() {


if (location != null) {
longitude = [Link]();
56
}
return longitude;
}

public booleancanGetLocation() {
return [Link];
}

public void showSettingsAlert() {


[Link] = new [Link](mContext);
[Link]("GPS Settings");
[Link]("GPS is not enabled. Do you want to go to settings
menu?");
[Link]("Settings", (dialog, which) -> {
Intent intent = new
Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
[Link](intent);
});
[Link]("Cancel", (dialog, which) ->[Link]());
[Link]();
}
@Override
public void onLocationChanged(@NonNull Location location) {
[Link] = location;
[Link] = [Link]();
[Link] = [Link]();
}
@Override
public void onProviderDisabled(@NonNull String provider) {
}
@Override
public void onProviderEnabled(@NonNull String provider) {
}
57
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public IBinderonBind(Intent arg0) {
return null;
}
}

• So now the Coding part is also completed.


• Now run the application to see the output.

Output:

Result:

Thus Android Application that implements GPS Location Information is


developed and executed successfully.
58
Ex. No. 09 Implement an application that writes data to the SD Card
Date:

Aim:

To develop an 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.
• Then type the Application name as “exno9″and click Next.
• Then select the Minimum SDK as shown below and click Next.
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

Designing layout for the Android Application:

• Click on app -> res -> layout -> activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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


<LinearLayoutxmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:orientation="vertical">

<EditText

59
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30dp" />

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Write Data"
android:textSize="30dp" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Read data"
android:textSize="30dp" />

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Clear"
android:textSize="30dp" />
</LinearLayout>

• Now click on Design and your application will look as given below.
• So now the designing part is completed.

60
Adding permissions in Manifest for the Android Application:

• Click on app -> manifests -> [Link].


• Now include the WRITE_EXTERNAL_STORAGE permissions in the
[Link] file as shown below.

Code for [Link]:

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


<manifest xmlns:android="[Link]
package="[Link].exno8" >
<uses-permission
android:name="[Link].WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission
android:name="[Link].READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Exno8" >
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>

61
• So now the Permissions are added in the Manifest.

Java Coding for the Android Application:

• Click on app -> java -> [Link].exno9 ->MainActivity.


• Then delete the code which is there and type the code as given below.

Code for [Link]:

package [Link].exno9;
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : AppCompatActivity() {


private lateinit var e1: EditText
private lateinit var write: Button
private lateinit var read: Button
private lateinit var clear: Button
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContentView([Link].activity_main)
e1 = findViewById([Link])
write = findViewById([Link])
read = findViewById([Link].button2)
clear = findViewById([Link].button3)
[Link] {

62
val message = [Link]()
try {
val f = File(getExternalFilesDir(null), "[Link]")
valfout = FileOutputStream(f)
[Link]([Link]())
[Link]()
[Link](baseContext, "Data Written in External Storage",
Toast.LENGTH_LONG).show()
} catch (e: Exception) {
[Link](baseContext, [Link], Toast.LENGTH_LONG).show()
}
}
[Link] {
var message: String?
valbuf = StringBuilder()
try {
val f = File(getExternalFilesDir(null), "[Link]")
val fin = FileInputStream(f)
val br = BufferedReader(InputStreamReader(fin))
while ([Link]().also { message = it } != null) {
[Link](message)
}
[Link]([Link]())
[Link]()
[Link]()
[Link](baseContext, "Data Received from External Storage",
Toast.LENGTH_LONG).show()
} catch (e: Exception) {
[Link](baseContext, [Link], Toast.LENGTH_LONG).show()
}
}
[Link] {
[Link]("") }
63
}
}

• So now the Coding part is also completed.


• Now run the application to see the output.

Output:

Result:

Thus Android Application that writes data to the SD Card is developed and
executed successfully.

64
Ex. No.10 Implement an application that creates an alert upon receiving a
Date: message

Aim:

To develop an 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 “exno10″and click Next.
• Then select the Minimum SDK as shown below and click Next.
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

Designing layout for the Android Application:

• Click on app -> res -> layout -> activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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


<LinearLayoutxmlns: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"

65
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>

• Now click on Design and your application will look as given below.
• So now the designing part is completed.

Java Coding for the Android Application:

• Click on app -> java -> [Link].exno10->MainActivity.


• Then delete the code which is there and type the code as given below.

Code for [Link]:

package [Link].exno10;
import [Link]
import [Link]
import [Link]

66
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : AppCompatActivity() {


private lateinit var notifyBtn: Button
private lateinit var editText: EditText

override fun onCreate(savedInstanceState: Bundle?) {


[Link](savedInstanceState)
setContentView([Link].activity_main)
notifyBtn = findViewById([Link])
editText = findViewById([Link])
createNotificationChannel()
[Link] {
// Note: SecondActivity was not found in the project, using MainActivity as
a placeholder.
val intent = Intent(this, MainActivity::[Link])
valpendingIntent = [Link](
this,
0,
intent,
PendingIntent.FLAG_IMMUTABLEor PendingIntent.FLAG_UPDATE_CURRENT
)
val builder = [Link](this, "default_channel")
.setSmallIcon([Link].ic_launcher)
.setContentTitle("New Message")
.setContentText([Link]())
67
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true)

valnotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
[Link](0, [Link]())
}
}
private fun createNotificationChannel() {
if ([Link].SDK_INT>= Build.VERSION_CODES.O) {
val name = "Default Channel"
valdescriptionText = "Channel for app notifications"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel("default_channel", name, importance).apply {
description = descriptionText
}
valnotificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
[Link](channel)
}
}
}

• So now the coding part is also completed.


• Now run the application to see the output.

68
Output:

Result:

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


developed and executed successfully.

69
Ex. No. 11 Write a mobile application that makes use of RSS Feed
Date:

Aim:

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

Procedure:

Creating a New project:

• Open Android Studio and then click on File -> New -> New project.
• Then type the Application name as “exno11″and click Next.
• Then select the Minimum SDK as shown below and click Next.
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

Designing layout for the Android Application:

• Click on app -> res -> layout -> activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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


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

<ListView
android:id="@android:id/list"
android:layout_width="match_parent"

70
android:layout_height="match_parent"/>
</LinearLayout>

• Now click on Design and your application will look as given below.
• So now the designing part is completed.

Adding permissions in Manifest for the Android Application:

• Click on app -> manifests -> [Link].


• Now include the INTERNET permissions in the [Link] file as
shown below.

Code for [Link]:

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


<manifest xmlns:android="[Link]
package="[Link].exno10" >
<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/Theme.Exno10" >
<activity
android:name=".MainActivity"
android:exported="true" >
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]"/>
</intent-filter>
</activity>
</application>
</manifest>

71
• So now the Permissions are added in the Manifest.

Java Coding for the Android Application:

• Click on app -> java -> [Link].exno11->MainActivity.


• Then delete the code which is there and type the code as given below.

Code for [Link]:

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

class MainActivity : ListActivity() {


private var headlines: MutableList<String> = ArrayList()
private var links: MutableList<String> = ArrayList()
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
// Since we are using ListActivity, we can set a layout or not.

72
// If we set a layout, it must contain a ListView with id android:id/list.
setContentView([Link].activity_main)
MyAsyncTask().execute()
}
private inner class MyAsyncTask : AsyncTask<Unit, Void, List<String>>() {
override fun doInBackground(vararg params: Unit): List<String>? {
valnewHeadlines = ArrayList<String>()
valnewLinks = ArrayList<String>()
try {
// Using a more reliable RSS feed for testing if needed
valurl = URL("[Link]
val factory = [Link]()
[Link]= false
valxpp = [Link]()
valinputStream = getInputStream(url)
if (inputStream == null) return null
[Link](inputStream, "UTF-8")
var insideItem = false
var eventType = [Link]
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
when {
[Link]("item", ignoreCase = true) ->insideItem = true
[Link]("title", ignoreCase = true) -> {
if (insideItem) [Link]([Link]())
}
[Link]("link", ignoreCase = true) -> {
if (insideItem) [Link]([Link]())
}
}
} else if (eventType ==
XmlPullParser.END_TAG&&[Link]("item", ignoreCase = true)) {
insideItem = false
73
}
eventType = [Link]()
}
headlines = newHeadlines
links = newLinks
return headlines
} catch (e: Exception) {
Log.e("MainActivity", "Error parsing RSS", e)
}
return null
}
override fun onPostExecute(result: List<String>?) {
if (result != null) {
val adapter = ArrayAdapter(this@MainActivity,
[Link].simple_list_item_1, result)
listAdapter= adapter
}
}
}
override fun onListItemClick(l: ListView, v: View, position: Int, id: Long) {
if (position <[Link]) {
valuri = [Link](links[position])
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
}
}
private fun getInputStream(url: URL): InputStream? {
return try {
val connection = [Link]()
[Link]= 5000
[Link]= 5000
[Link]()
} catch (e: IOException) { null
74
}
}
}

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

75
Ex. No. 12 Develop a mobile application to send an email
Date:

Aim:

To develop an Android Application to send an Email.

Procedure:

Creating a New project:

• Open Android Studio and then click on File -> New -> New project.
• Then type the Application name as “exno12″and click Next.
• Then select the Minimum SDK as shown below and click Next.
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

Designing layout for the Android Application:

• Click on app -> res -> layout -> activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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


<LinearLayoutxmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:orientation="vertical" >
<EditText
android:id="@+id/txtTo"

76
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="To"/>
<EditText
android:id="@+id/txtSub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Subject"/>
<EditText
android:id="@+id/txtMsg"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="Message"/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Send"
android:id="@+id/btnSend"/>
</LinearLayout>

Adding permissions in Manifest for the Android Application:

• Click on app -> manifests -> [Link].


• Now include the INTERNET permissions in the [Link] file as
shown below.

Code for [Link]:

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


<manifest xmlns:android="[Link]
xmlns:tools="[Link]

77
package="[Link].exno12" >
<uses-permission android:name="[Link]"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Exno11"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name="[Link]"
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]"/>
</intent-filter>
<intent-filter>
<action android:name="[Link]"/>
<category android:name="[Link]"/>
<data android:mimeType="message/rfc822"/>
</intent-filter>
</activity>
</application>
</manifest>

• So now the Permissions are added in the Manifest.

Java Coding for the Android Application:

• Click on app -> java -> [Link].exno12 ->MainActivity.


• Then delete the code which is there and type the code as given below.

78
Code for [Link]:

package [Link].exno12;
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity :AppCompatActivity() {


private lateinit var eTo: EditText
private lateinit var eSubject: EditText
private lateinit var eMsg: EditText
private lateinit var btn: Button
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContentView([Link].activity_main)
eTo = findViewById([Link])
eSubject = findViewById([Link])
eMsg = findViewById([Link])
btn = findViewById([Link])
[Link] {
val intent = Intent(Intent.ACTION_SEND)
[Link](Intent.EXTRA_EMAIL, arrayOf([Link]()))
[Link](Intent.EXTRA_SUBJECT, [Link]())
[Link](Intent.EXTRA_TEXT, [Link]())
[Link]= "message/rfc822"
startActivity([Link](intent, "Choose Mail App"))
}
}
}

• So now the Coding part is also completed.


• Now run the application to see the output.
79
Output:

Result:

Thus Android Application for sending an email is developed and executed


successfully.

80
Ex. No. 13 Develop a Simple Android Application for Native Calculator
Date:

Aim:

To develop a Simple Android Application for Native Calculator.

Procedure:

Creating a New project:

• Open Android Studio and then click on File -> New -> New project.
• Then type the Application name as “exno13″and click Next.
• Then select the Minimum SDK as shown below and click Next.
• Then select the Empty Activity and click Next.
• Finally click Finish.
• It will take some time to build and load the project.
• After completion it will look as given below.

Designing layout for the Android Application:

• Click on app -> res -> layout -> activity_main.xml.


• Now click on Text as shown below.
• Then delete the code which is there and type the code as given below.

Code for 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"
android:layout_margin="20dp">
<LinearLayout
android:id="@+id/linearLayout1"

81
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"
82
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"
83
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.
• So now the designing part is completed.

Java Coding for the Android Application:

• Click on app -> java -> [Link].exno13 ->MainActivity.


• Then delete the code which is there and type the code as given below.

Code for [Link]:

package [Link].exno13;
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]
import [Link]

class MainActivity : AppCompatActivity(), [Link] {

private lateinit var num1: EditText


private lateinit var num2: EditText
private lateinit var add: Button
private lateinit var sub: Button
private lateinit var mul: Button

84
private lateinit var div: Button
private lateinit var result: TextView

override fun onCreate(savedInstanceState: Bundle?) {


[Link](savedInstanceState)
setContentView([Link].activity_main)
num1 = findViewById([Link].editText1)
num2 = findViewById([Link].editText2)
add = findViewById([Link])
sub = findViewById([Link])
mul = findViewById([Link])
div = findViewById([Link])
result = findViewById([Link])

[Link](this)
[Link](this)
[Link](this)
[Link](this)
}

override fun onClick(v: View?) {


val sNum1 = [Link]()
val sNum2 = [Link]()
if ([Link](sNum1) || [Link](sNum2)) {
return
}
val n1 = [Link]()
val n2 = [Link]()
var res = 0f
var oper = ""
when (v?.id) {
[Link]-> {
85
oper = "+"
res = n1 + n2
}
[Link]-> {
oper = "-"
res = n1 - n2
}
[Link]-> {
oper = "*"
res = n1 * n2
}
[Link]-> {
oper = "/"
res = if (n2 != 0f) n1 / n2 else 0f
}
}
[Link]= "$n1 $oper $n2 = $res"
}
}

• So now the Coding part is also completed.


• Now run the application to see the output.

86
Output:

Result:

Thus a Simple Android Application for Native Calculator is developed and


executed successfully.

87

You might also like