Intent i = new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_FROM_BACKGROUND);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT| PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this).setAutoCancel(true).setContentTitle(title).setContentText(body).setSmallIcon(R.drawable.atlantic_applogo).setLargeIcon(icon).setDefaults(Notification.DEFAULT_ALL).setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
从应用程序图标打开应用程序但从通知中打开应用程序时,它工作正常,如果单击新通知,则如果应用程序处于前台,则什么也不会发生。
答案 0 :(得分:0)
OP的解决方案:
i.setPackage(null);
i.setFlags(Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_RECEIVER_NO_ABORT );
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i,
PendingIntent.FLAG_UPDATE_CURRENT |
PendingIntent.FLAG_ONE_SHOT |
PendingIntent.FLAG_IMMUTABLE);