我想通过通知打开我的应用程序,这是填充意图
Intent viewIntent = new Intent(this, MainActivity.class);
viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
viewIntent.putExtra(MainActivity.EXTRA_1, "someExtra");
viewIntent.putExtra(MainActivity.EXTRA_2, "someExtra");
viewIntent.setAction("action name");
PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
return viewPendingIntent;
如果从现在开始这个意图是午餐意图,如果我尝试从最近的应用程序中打开应用程序,他将触发相同的通知意图
我不认为通知意图将是午餐意图
答案 0 :(得分:0)
我正在使用此代码在点击通知时打开MainActivity。
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);