Android allows to put notification into the titlebar of your
application. The user can expand the notification bar and by selecting
the notification the user can trigger another activity.
Notifications in Android are represented by the
The
Activity-MainActivity.java
private static final int MY_NOTIFICATION_ID = 1;
private NotificationManager notificationManager;
private Notification myNotification;
private final String myBlog = "http://niravranpara.blogspot.com/";
buttonSend.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(R.drawable.ic_launcher,
"Notification!", System.currentTimeMillis());
Context context = getApplicationContext();
String notificationTitle = "Exercise of Notification!";
String notificationText = "http://niravranpara.blogspot.com/";
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse(myBlog));
PendingIntent pendingIntent = PendingIntent.getActivity(
MainActivity.this, 0, myIntent,
Intent.FLAG_ACTIVITY_NEW_TASK);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.setLatestEventInfo(context, notificationTitle,
notificationText, pendingIntent);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
}
});
Notifications in Android are represented by the
Notification class.The
Notification.Builderhttp://developer.android.com/reference/android/app/Notification.Builder.html provides an builder interface to create an Notification object.Activity-MainActivity.java
private static final int MY_NOTIFICATION_ID = 1;
private NotificationManager notificationManager;
private Notification myNotification;
private final String myBlog = "http://niravranpara.blogspot.com/";
buttonSend.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(R.drawable.ic_launcher,
"Notification!", System.currentTimeMillis());
Context context = getApplicationContext();
String notificationTitle = "Exercise of Notification!";
String notificationText = "http://niravranpara.blogspot.com/";
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse(myBlog));
PendingIntent pendingIntent = PendingIntent.getActivity(
MainActivity.this, 0, myIntent,
Intent.FLAG_ACTIVITY_NEW_TASK);
myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.setLatestEventInfo(context, notificationTitle,
notificationText, pendingIntent);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
}
});
<uses-permission android:name="android.permission.VIBRATE"/>
No comments:
Post a Comment