【问题标题】:Buttons in android push notificationandroid推送通知中的按钮
【发布时间】:2016-08-12 12:58:43
【问题描述】:

我正在 android 设备中推送通知消息,并遵循 GCM 文档供我参考,我有这样的场景,在通知本身中我必须显示按钮并且用户点击它会触发相应的操作。

从 GCM 文档中,我们可以在通知负载中添加 click_action 以在用户触摸通知时触发操作...

如何在通知消息中显示按钮(如接受/拒绝)?

【问题讨论】:

  • 让我告诉你一个建议。现在 Google 正在使用 Firebase Cloud Messaging,他们有很多教程来运行各种功能(推送通知、社交网络登录、云数据库等)我真的推荐它:-) firebase.google.com/docs

标签: android push-notification notifications google-cloud-messaging gcmtaskservice


【解决方案1】:

您可以在Notification.Builder 中使用.addAction

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

请参阅此link

【讨论】:

【解决方案2】:

无法向通知消息添加操作按钮。这可能是稍后添加的功能,但目前不存在。

通知消息允许您创建一个非常特定类型的通知,如果您想要一个非常自定义的通知,那么您应该使用数据消息(不是通知消息),然后在收到消息时使用 Notification.Builder 生成您的自定义通知具有尽可能多的功能:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多