带有“null”PendingIntent 的通知

问题描述 投票:0回答:3

我正在尝试在 Android 中实现通知。

现在我有一个问题,我不想有一个

PendingIntent
用户会打开任何
Activity
。我怎样才能做到这一点?

android-notifications android-pendingintent
3个回答
56
投票
PendingIntent contentIntent = PendingIntent.getActivity(
    getApplicationContext(),
    0,
    new Intent(), // add this
    PendingIntent.FLAG_UPDATE_CURRENT);

7
投票

以下方法有效并且看起来更简单:

PendingIntent pi = PendingIntent.getActivity(context, 0, null, 0);

在不启动后续活动的情况下收到通知对我来说似乎非常明智 - 例如“该起床了!”


0
投票
注意:当 PendingIntent 的基本操作为空时,可能会导致权限泄漏。请参阅 CVE-2014-8609:

https://seclists.org/fulldisclosure/2014/Nov/81

© www.soinside.com 2019 - 2024. All rights reserved.