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

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

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

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

最佳答案
这是在设备侧而不是服务器上完成的.

完成Google Cloud Messaging完成后

考虑在设备上创建Notifications.

这是代表带按钮的通知的片段,如第二个链接所示:

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 通过adb shell命令查看内存,CPU,启动时间,电量等...
Monkey Android app稳定性测试工具之Monkey使用教程 by:授客...
Android 常见adb命令 by:授客 QQ:1033553122 1、 查看所有已...
这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...