Reputation: 59
The default notification click behavior is lunching the activity, but I want to show a toast or call a method instead. How do I do that?
//**cleareble notification**//
NotificationManager notificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification noti = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentIntent(
PendingIntent.getActivity(this, 0, getIntent(),
PendingIntent.FLAG_UPDATE_CURRENT))
.setContentTitle("HELLO world")
.setContentText("PLEASE CHECK WE HAVE UPDATED NEWS")
.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("ticker message")
.setWhen(System.currentTimeMillis()).build();
//noti.flags |= Notification.FLAG_NO_CLEAR;
notificationManager.notify(0, noti);
Upvotes: 1
Views: 1034
Reputation:
Look at this link in the Android developper site Building a Notification
Basically you create a PendingIntent and use setContentIntent method of your Notification.Builder.
Look at section Define the Notification's Action and Set the Notification's Click Behavior
Upvotes: 1