Android:空 PendingIntent
Android : Null PendingIntent
我正在尝试为包含通知的广播接收器创建一个 PendingIntent,但不知何故我得到了一个空的 PendingIntent returned。这是没有意义的,因为只指定了 1 种情况 return null PendingIntent 并且如果 PendingIntent.FLAG_NO_CREATE 作为标志选项传递。
这是我的 PendingIntent 代码。在调试器 pendIntent = null 之后。
Intent notificationIntent = new Intent(context, LocalPushBroadcastReceiver.class);
notificationIntent.putExtra(LocalPushBroadcastReceiver.NOTIFICATION_ID_ARG, pushId);
notificationIntent.putExtra(LocalPushBroadcastReceiver.NOTIFICATION_ARG, notification);
notificationIntent.setData(Uri.parse("LocalPush:" + pushId + notification.toString()));
PendingIntent pendIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, 0);
我尝试了很多其他的标志/选项。我尝试从 onClick / onStart / 无处不在调用此代码。我正在使用最新版本的 Android Studio 并使用最新的 sdk 版本 25 进行编译。此外,清单中正确定义了 LocalPushBroadcastReceiver。
这很奇怪,因为我在另一台机器上的另一个应用程序中使用了完全相同的代码,但我不知道我缺少什么配置。我将不胜感激任何想法。谢谢!
看来我的问题与我试图作为参数传递给 PendingIntent 的通知的大小有关。 IMO 日志记录/错误处理在这里可能会更好一些,但基本上是因为我将一个大的位图作为 BigPictureStyle 附加到我的通知中,Parcelable 最终变得太大,需要以不同的方式处理。
tl;博士
我避免将通知作为 Parcelable 传递,而是传递一个 id,以便在我稍后收到广播时使用它来获得正确的通知。感谢pskink 协助调试
我正在尝试为包含通知的广播接收器创建一个 PendingIntent,但不知何故我得到了一个空的 PendingIntent returned。这是没有意义的,因为只指定了 1 种情况 return null PendingIntent 并且如果 PendingIntent.FLAG_NO_CREATE 作为标志选项传递。
这是我的 PendingIntent 代码。在调试器 pendIntent = null 之后。
Intent notificationIntent = new Intent(context, LocalPushBroadcastReceiver.class); notificationIntent.putExtra(LocalPushBroadcastReceiver.NOTIFICATION_ID_ARG, pushId); notificationIntent.putExtra(LocalPushBroadcastReceiver.NOTIFICATION_ARG, notification); notificationIntent.setData(Uri.parse("LocalPush:" + pushId + notification.toString())); PendingIntent pendIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, 0);
我尝试了很多其他的标志/选项。我尝试从 onClick / onStart / 无处不在调用此代码。我正在使用最新版本的 Android Studio 并使用最新的 sdk 版本 25 进行编译。此外,清单中正确定义了 LocalPushBroadcastReceiver。
这很奇怪,因为我在另一台机器上的另一个应用程序中使用了完全相同的代码,但我不知道我缺少什么配置。我将不胜感激任何想法。谢谢!
看来我的问题与我试图作为参数传递给 PendingIntent 的通知的大小有关。 IMO 日志记录/错误处理在这里可能会更好一些,但基本上是因为我将一个大的位图作为 BigPictureStyle 附加到我的通知中,Parcelable 最终变得太大,需要以不同的方式处理。
tl;博士
我避免将通知作为 Parcelable 传递,而是传递一个 id,以便在我稍后收到广播时使用它来获得正确的通知。感谢pskink 协助调试