使用操作按钮创建GCM推送消息

时间:2015-04-23 15:30:29

标签: android google-cloud-messaging

我见过一些发送推送通知的应用程序,这些推送通知具有自定义按钮以执行某些操作。

我在这里查看了GCM推送通知服务器文档: https://developer.android.com/google/gcm/server-ref.html#table1

但是没有关于如何做到这一点的参考。

1 个答案:

答案 0 :(得分:4)

This is done on the side of the device and not the server.

After finishing the complete implementation of Google Cloud Messaging

Consider creating Notifications on the device.

Here is snippet representing a notification with buttons, as pointed at the second link:

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();