【问题标题】:Notification with "null" PendingIntent带有“null”PendingIntent 的通知
【发布时间】:2011-05-13 00:47:18
【问题描述】:

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

现在我有一个问题,我不想让用户打开任何ActivityPendingIntent。我该怎么做?

【问题讨论】:

  • 简单地将contentIntent字段设置为null有问题吗?
  • 为什么会有用户无法操作的通知?

标签: android-notifications android-pendingintent


【解决方案1】:
PendingIntent contentIntent = PendingIntent.getActivity(
    getApplicationContext(),
    0,
    new Intent(), // add this
    PendingIntent.FLAG_UPDATE_CURRENT);

【讨论】:

  • 有趣的注意,如果你只是传递“null”而不是挂起的意图,通知是无法点击的。
【解决方案2】:

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

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

在不启动后续活动的情况下发出通知对我来说似乎很明智 - 例如“该起床了!.

【讨论】:

  • 适用于早期版本的 Andorid,但可以符合 ICS 上的 RTE。
猜你喜欢
  • 2023-03-27
  • 2012-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多