我正在 android 设备中推送通知消息,并遵循 GCM 文档供我参考,我有这样的场景,在通知本身中我必须显示按钮并且用户单击它将触发相应的操作。
从 GCM 文档中,我们可以在通知负载中添加 click_action 以在用户触摸通知时触发操作...
如何在通知消息中显示按钮(如接受/拒绝)?
我正在 android 设备中推送通知消息,并遵循 GCM 文档供我参考,我有这样的场景,在通知本身中我必须显示按钮并且用户单击它将触发相应的操作。
从 GCM 文档中,我们可以在通知负载中添加 click_action 以在用户触摸通知时触发操作...
如何在通知消息中显示按钮(如接受/拒绝)?
您可以
.addAction
在Notification.Builder
.
Notification notification = new Notification.Builder(context)
// Show controls on lock screen even when user hides sensitive content.
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.ic_stat_player)
// Add media control buttons that invoke intents in your media service
.addAction(R.drawable.ic_accept, "Accept", prevPendingIntent) // #0
.addAction(R.drawable.ic_reject, "Reject", pausePendingIntent) // #1
// Apply the media style template
编辑 1
请参阅此链接。
无法向通知消息添加操作按钮。这可能是稍后添加的功能,但目前不存在。
通知消息允许您创建非常特定类型的通知,如果您想要一个非常自定义的通知,那么您应该使用数据消息(不是通知消息),然后在收到消息时使用 Notification.Builder 生成您的自定义通知具有尽可能多的功能:)