我收到带有自定义 Uri 方案的推送通知:myapp://main
在我的onReceive
我创建一个通知:
public void createNotification(Context context, String title, String message, String summary, Uri uri) {
Notification.Builder notification = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(R.drawable.ic_launcher)
.setDefaults(Notification.DEFAULT_LIGHTS)
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && summary != null)
notification.setSubText(summary);
Intent intent = new Intent("android.intent.action.VIEW", uri);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
notification.setContentIntent(pendingIntent);
Notification noti;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
noti = notification.build();
else
noti = notification.getNotification();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
}
然后当我点击该通知时,它会打开一个新的 Activity,它是我的 MainActivity。但它似乎也创建了一个全新的过程,而不是仅仅打开我当前正在运行的应用程序。
我缺少一些标志吗?