Send a notification

protected void sendnotification (String title, String message) {
   String ns = Context.NOTIFICATION_SERVICE;
   NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
 
   int icon = R.drawable.icon;
   CharSequence tickerText = message;
   long when = System.currentTimeMillis();

   Notification notification = new Notification(icon, tickerText, when);

   Context context = getApplicationContext();
   CharSequence contentTitle = title;
   CharSequence contentText = message;
   Intent notificationIntent = new Intent(this, AndroToDo.class);
   PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

   notification.flags = Notification.FLAG_AUTO_CANCEL;
   notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
   mNotificationManager.notify(NOTIFICATION_ID, notification);
}

Add a Comment