【发布时间】:2017-01-28 06:48:47
【问题描述】:
我已经使用 fcm 进行通知并且它正确出现,但是当我尝试在通知中添加添加按钮时它没有显示。
我的代码
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("New Message From Film")
.setContentText(messageBody)
.setAutoCancel(true)
.addAction(R.drawable.pp, "Accept",pendingIntent)
.addAction(R.drawable.pp, "Reject",pendingIntent)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
【问题讨论】:
-
我们可以看到
pendingIntent代码吗? -
我对其进行了测试,它在 lolypop 和 pre lolypop 设备上运行良好!如果可能,添加更多代码。
-
@pRaNaY 你确定我更新了代码请检查
-
@Seyyed 在 marashmellow 中测试通知即将到来,但按钮未显示
-
在您的案例中应该有 3 种不同的意图,一种用于通知意图,第二种用于操作接受,第三种用于操作拒绝。您不应该对所有 3 个都使用相同的待处理意图。参考这个stackoverflow.com/a/15521314/1576416
标签: android firebase notifications android-notifications