Send Notification : Notification « Core Class « Android






Send Notification

  

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

 class Helper {
    public static void sendNotification(Context context, int notificationId,
            String title, String content) {
        // Show a notification.
        final NotificationManager nMgr = (NotificationManager) context.getSystemService(
                context.NOTIFICATION_SERVICE);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
        Notification notif = new Notification(R.drawable.icon, title, 
                System.currentTimeMillis());
        notif.setLatestEventInfo(context, title, (content == null) ? "" : content, contentIntent);
        nMgr.notify(notificationId, notif);
    }
}

   
    
  








Related examples in the same category

1.Notification event
2.How to use Notification
3.Look up the notification manager service
4.Cancel the notification that we started
5.Using NotificationManager
6.Demonstrates adding notifications to the status bar