PendingIntent.getBroadcast 棉绒警告

PendingIntent.getBroadcast lint warning

有关于使用 PendingIntent.getBroadcast 作为通知内容意图的新警告:

builder.setContentIntent(PendingIntent.getBroadcast(FirebaseNotification.this, newID,
                                                  new Intent(getString(R.string.notif_broadcast))
                                                          .setClass(FirebaseNotification.this, NotificationActions.class)
                                                          .putExtra(getString(R.string.thumbnail), bitmap);

Lint 消息:

Notifications should only launch a BroadcastReceiver from notification actions (addAction)

Notifications should only launch a BroadcastReceiver from notification actions (addAction) (This BroadcastReceiver intent is launched from a notification; this is discouraged except as notification actions)

我在文档中的任何地方都没有看到这一点,那么为什么现在不鼓励这样做呢?是否为了用户体验并提供通知可以做什么的清晰上下文?

如果点击通知发送广播,对用户来说意义不大。预期的行为是打开最初发送通知的实际应用程序,所以我不确定发送另一个通知(我认为这是你的代码实现的)是否是好的用户体验。

他们确实提到这是 material design documentation 他们说:

When the user taps a notification, they should be taken to a screen in your app that relates directly to that notification and lets them take immediate action.