Beruflich Dokumente
Kultur Dokumente
No : 10
CREATES AN ALERT UPON RECEIVING A MESSAGE
Date :
AIM :
To implement an application that creates an alert upon receiving a message
Procedure and Program:
(Note: Internet Connection is Mandatory to run this application)
Step 1 : Open Eclipse from Android ADT Bundle
Step 2 : Go to File Menu Choose New Android Application Project
Step 3 : In the displayed window type Application name as Ex.No 10 , and click Next 4 times.
Step 4 : In the Last window type Activity Name and Layout Name, and press Finish
OR
Step 7 : b. Using XML code Choose activity_main.xml,
<Button
android:id="@+id/btnGenerateNotifications"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="186dp"
android:text="Click me to Generate a Notification" />
</RelativeLayout>
sub_main.xml (File#2)
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SubActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Android 6.0 or Marshmallow is high in the news these
days. These headlines about Marshmallow are making people think whether their
current Android device will be upgraded to the latest version or they will be
left behind. A basic measure would be that most of the devices which came
with Android 5.0 (Lollipop) out of the box will be updated to the latest
Android 6.0. This post tries to list up the devices for which Android 6.0
update is imminent."
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button) findViewById(R.id.btnGenerateNotifications);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(MainActivity.this,
SubActivity.class);
PendingIntent pendIntent = PendingIntent.getActivity(
MainActivity.this, 0, intent, 0);
builder.setContentText("ContentText,ContentText,ContentText,ContentText
,ContentText,ContentText,ContentText");
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setTicker("Message from
Developer.Android....");
builder.setAutoCancel(true);
builder.setContentIntent(pendIntent);*/
.setContentTitle("Marshmallow@developer.android.in")
.setContentText("Android 6.0")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pendIntent).setAutoCancel(true)
.build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notiMail);
}
});
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
package com.example.ex.no10;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.sub, menu);
return true;
}
RESULT:
Thus the above android application has been run successfully.