我在 android 中有一个应用程序,在某些情况下我想将一个 Activity 带到前台。我为此使用 NotificationManager。这是我的代码。问题是,第一次成功地将 Activity 带到前面,但后来却没有。此外,此代码是从服务运行的。
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(contentIntent)
.setContentTitle("Bring me front!")
.setContentText("Bring me!!! BRING!!!")
.setFullScreenIntent(contentIntent, true);
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
最佳答案
NotificationManager 具有(未记录的)行为,如果您发布与已激活通知的 ID 匹配的新通知,它将忽略 fullScreenIntent 字段。
关于android - setFullScreenIntent 第二次不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17616631/