Anh*_*nun 8 notifications android android-notifications android-activity
我在 android 中有一个应用程序,在某些情况下我想将一个 Activity 带到前台。我为此使用NotificationManager。这是我的代码。问题是,活动第一次成功地被带到前面,但后来却没有。此外,此代码是从服务运行的。
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());
Run Code Online (Sandbox Code Playgroud)
小智 6
NotificationManager 有一个(未记录的)行为,即如果您发布与已处于活动状态的通知的 ID 相匹配的新通知,它将忽略fullScreenIntent 字段。
有几点需要检查:
FLAG_ACTIVITY_NEW_TASK(并且可能FLAG_ACTIVITY_CLEAR_TOP)确保该活动被带到前面。fullScreenIntent.| 归档时间: |
|
| 查看次数: |
5583 次 |
| 最近记录: |