微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/android/431255.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐