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

标签 android google-cloud-messaging

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

我在这里查看了 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/

相关文章:

java - 如何在android honeycomb中编辑EditTextPreference?

android - 安装 apk : INSTALL PARSE_FAILED_NOT_APK 时出错

android-maven-plugin 和资源过滤

ios - 是否有一些已知方法可以改进 Apple Push Notifications 存储转发功能以存储多个通知?

android - Google Cloud Messaging 不适用于公司网络上的 4.1.2 设备

android - 停止应用程序从 fcm/gcm 获取通知

android - 如何将 Instagram 拍成正方形照片

android - WebView 中的 TalkBack 辅助功能

java - 无法使 Google Cloud Message 保持 Activity 状态

php - GCM 丢弃消息