我见过一些发送推送通知的应用程序,这些应用程序具有用于执行特定操作的自定义按钮。
我在这里查看了 GCM 推送通知服务器文档: https://developer.android.com/google/gcm/server-ref.html#table1
但是没有关于如何做到这一点的引用。
最佳答案
这是在设备端而不是服务器端完成的。
完成后完整执行Google Cloud Messaging
考虑创建 Notifications在设备上。
这是代表带有按钮的通知的 fragment ,如第二个链接所示:
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_prev, "Previous", prevPendingIntent) // #0
.addAction(R.drawable.ic_pause, "Pause", pausePendingIntent) // #1
.addAction(R.drawable.ic_next, "Next", nextPendingIntent) // #2
// Apply the media style template
.setStyle(new Notification.MediaStyle()
.setShowActionsInCompactView(1 /* #1: pause button */)
.setMediaSession(mMediaSession.getSessionToken())
.setContentTitle("Wonderful music")
.setContentText("My Awesome Band")
.setLargeIcon(albumArtBitmap)
.build();
关于android - 使用操作按钮创建 GCM 推送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29827997/