You are on page 1of 5

Department of Computer Engineering

Date: - / /2023
Roll No.: - B-644

Experiment - 08

Aim: To develop an android application that creates an alert upon receiving a message.

Objective: To create an application that creates an alert upon receiving a message.

Software:

• Android Studio

Android Studio is the official Integrated Development Environment (IDE) for Android
app development. It is purpose-built for Android to accelerate your development and help
you build the highest-quality apps for every Android device. Android Studio is based on
the powerful code editor and developer tools from IntelliJ IDEA. It offers even more
features that enhance your productivity when building Android apps, such as a flexible
Gradle- based build system. Android Studio is available for download on Windows,
macOS and Linux based operating systems.

• The Android SDK (Starter Package)

The Android SDK stands for Android Software Development Kit, which is developed by
Google for the Android Platform. The SDK Starter Package is a part of the Android SDK
that includes only the core SDK Tools, which you can use to download the rest of the
SDK packages (such as the latest Android platform).

• Gradle

Gradle is a build automation tool used to automate the creation of applications. It is


known for its flexibility to build software and is an open-source build automation tool
flexible enough to build almost any type of software. Gradle makes few assumptions
about what you’re trying to build or how to build it. This makes Gradle particularly
flexible.

• Java Development Kit (JDK) 5

JDK 5 stands for Java Development Kit 5. It is a development environment for building
applications, applets, and components using the Java programming language. It is
supported on Microsoft Windows running Intel IA32, 100% compatible processors, and
AMD Opteron 32.

Program:
Department of Computer Engineering

Code for Activity_main.xml:

?
1<?xml version="1.0" encoding="utf-8"?>
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">
7
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</LinearLayout>
30
Code for MainActivity.java:
?
package com.example.exno10;

import android.app.Notification; import


android.app.NotificationManager; import
Department of Computer Engineering

android.app.PendingIntent; import
android.content.Intent; import
android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View; import
android.widget.Button; import
android.widget.EditText;

public class MainActivity extends AppCompatActivity


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

notify= (Button) findViewById(R.id.button);


e= (EditText) findViewById(R.id.editText);

notify.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
PendingIntent pending = PendingIntent.getActivity(MainActivity.this, 0,
intent,
0); Notification noti = new
Notification.Builder(MainActivity.this).setContentTitle("New
Message").setContentText(e.getText().toString()).setSmallIcon(R.mipmap.ic_launcher).s
etContentIntent(pending).build();
NotificationManager manager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
manager.notify(0, noti);
}
});
}
Department of Computer Engineering

Output:
Department of Computer Engineering

Conclusion: Thus, we have successfully developed and executed a Simple Android


Application that sends alert on receiving a message.

You might also like