【发布时间】:2021-06-19 09:44:11
【问题描述】:
我在服务中记录了这个:
intent = new Intent(this,MainActivity_Large.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this,CHANNEL_ID)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setAutoCancel(true)
.setChannelId(CHANNEL_ID)
.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(R.drawable.ant_intro)
.setContentTitle("Anttack")
.setContentText("Continues")
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
// .setPriority(2)
.setContentIntent(pendingIntent);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder.setCategory(Notification.CATEGORY_SERVICE);
}
notification = builder.build();
startForeground(1, notification);
设备进入睡眠状态并唤醒后,屏幕上会显示一条通知。如果你点击它,最小化的活动将被恢复。
如何跟踪 PendingIntent 的完成情况?
也许有人知道如何使用 PendingIntent.onFinished?
【问题讨论】:
-
您希望在点击通知时启动一个全新的活动,而不是最小化的活动?你能详细说明一下吗?
-
相同的折叠活动被恢复。
-
看起来将被带到前台的Activity属于您自己的应用程序。如果我理解正确,您需要知道用户从通知中触发了 PendingIntent 而不是显示的 Activity 因为用户点击了启动器图标。这是正确的吗?
-
是的。没错。
标签: java android android-pendingintent