Android Notifications

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 Notification class.

The Notification.Builder provides an builder interface to create an Notification object. 
  private static final int MY_NOTIFICATION_ID = 1;
   private NotificationManager notificationManager;
    private Notification myNotification;
    private final String myBlog = ""; 

    buttonSend.setOnClickListener(new Button.OnClickListener() {

            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 = "";
                Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri
                PendingIntent pendingIntent = PendingIntent.getActivity(
                        MainActivity.this, 0, myIntent,
                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"/>

Android Notifications Android Notifications Reviewed by Nirav Ranpara on 11:44 PM Rating: 5

Random Posts

My Android Tuts. Powered by Blogger.