0

我在android设备中执行推送通知消息,并且遵循GCM文档供我参考,并且我有通知本身中必须显示按钮并且用户单击它的情况将触发相应的操作。android推送通知中的按钮

从GCM文件,通知有效载荷,我们可以添加click_action当用户触摸通知来触发动作......

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

+0

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

回答

2

您可以在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 

EDIT 1

参考此link

+0

哪个Jar文件来自Notification.Builder ..我在gcm-server-1.0.2.jar中看不到任何类 –

+0

它在'GCM'的服务类中。看看这个链接https://developer.android.com/guide/topics/ui/notifiers/notifications.html –

-1

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

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