How To Open App In Notification In Android?
In my app, when completing a task in async file, it shows a notification with this code NotificationManager notificationManager = (NotificationManager) context.getSystemService
Solution 1:
You need an Intent
, sample code:
NotificationManagernotificationManager= (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notificationnotification=newNotification(icon, message, when);
IntentnotificationIntent=newIntent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntentintent= PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
This will open your MainActivity
Post a Comment for "How To Open App In Notification In Android?"