0% found this document useful (0 votes)
3 views

MCLExp9

Mobile computing 3rd Exp

Uploaded by

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

MCLExp9

Mobile computing 3rd Exp

Uploaded by

priti.rumao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Vidyavardhini’s College of Engineering & Technology

Department of Computer Engineering


Academic Year: 2023-24

EXPERIMENT NO. 9
AIM: Implement an application that creates an alert upon receiving a message.

Procedure:
Creating a new project:
1. Open Android Studio and then click on File -> New -> New project.
2. Then type the Application name as “ex.no.9″ and click Next.
3. Then select the Minimum SDK and click Next.
4. Then select the Empty Activity and click Next.
5. Finally click Finish.
It will take some time to build and load the project.
Designing layout for the Android Application:
1. Click on app -> res -> layout -> activity_main.xml.
2. Now click on Text.
3. 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- android:layout_height="wrap_cont


8"?> ent"
<LinearLayout xmlns:android= android:singleLine="true"
"http://schemas.android.com/apk/ android:textSize="30sp" />
res/android"
<Button
android:layout_width="match_paren android:id="@+id/button"
t"
android:layout_width="wrap_cont
android:layout_height="match_paren ent"
t"
android:layout_margin="10dp" android:layout_height="wrap_cont
android:orientation="vertical"> ent"

<TextView android:layout_margin="30dp"

android:layout_width="wrap_conten android:layout_gravity="center"
t" android:text="Notify"
android:textSize="30sp"/>
android:layout_height="wrap_conten
t" </LinearLayout>
android:text="Message"
android:textSize="30sp" />

<EditText
android:id="@+id/editText"

android:layout_width="match_paren
t
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
Academic Year: 2023-24

4. Now click on Design. This completes design part.


Java Coding for the Android Application:
1. Click on app -> java -> com.example.exno9 -> MainActivity.
2. Then delete the code which is there and type the code as given below.
Code for MainActivity.java:

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


com.example.exno9; e= (EditText) findViewById(R.id.editText);
import
android.app.Notificat super.onCreate(savedInstanceState);
ion; setContentView(R.layout.activity_main);
import
android.app.Notificat notify.setOnClickListener(new View.OnClickListener()
ionManager; {
import @Override
android.app.PendingI public void onClick(View v)
ntent; {
import Intent intent = new Intent(MainActivity.this,
android.content.Inten SecondActivity.class);
t; PendingIntent pending =
import PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
android.os.Bundle; Notification noti = new
import Notification.Builder(MainActivity.this).setContentTitle("New
android.support.v7.ap Message").setContentText(e.getText().toString()).setSmallIcon
p.AppCompatActivit (R.mipmap.ic_launcher).setContentIntent(pending).build();
y; NotificationManager manager =
import (NotificationManager)
android.view.View; getSystemService(NOTIFICATION_SERVICE);
import noti.flags |= Notification.FLAG_AUTO_CANCEL;
android.widget.Butto manager.notify(0, noti);
n; }
import });
android.widget.EditT }
ext; }

public class
MainActivity extends
AppCompatActivity
{
Button notify;
EditText e;
@Override
protected void
onCreate(Bundle
savedInstanceState)
{
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
Academic Year: 2023-24

OUTPUT:

CONCLUSION: Thus, Android Application that creates an alert upon receiving a message is
developed and executed successfully.
Vidyavardhini’s College of Engineering & Technology
Department of Computer Engineering
Academic Year: 2023-24

You might also like