【问题标题】:Creating GCM Push Messages with action buttons使用操作按钮创建 GCM 推送消息
【发布时间】:2015-04-23 15:30:28
【问题描述】:

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

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

但没有关于如何执行此操作的参考。

【问题讨论】:

    标签: android google-cloud-messaging


    【解决方案1】:

    这是在设备端而不是服务器端完成的。

    完成Google Cloud Messaging的完整实现后

    考虑在设备上创建Notifications

    这里是 sn-p 表示带有按钮的通知,如第二个链接所示:

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

    【讨论】:

    • 有没有办法在应用程序关闭时显示操作按钮?
    • @Borzh 应用是否在前台,通知会独立出现在系统的通知栏上。
    • 重启手机/模拟器,但不要启动应用。发送通知。你会看到什么都没有发生。这是因为一旦您启动应用程序,您的 FCM 服务将保持活动状态,直到下次重新启动。但是当你重新启动时,没有打开应用程序,该服务是不活动的。这个世界上没有魔法。
    • @Borzh 您缺少其他一些代码...我建议创建一个包含所有详细信息和您尝试过的内容的新问题。这是推送 FCM 消息的目的......从用户的角度来看,每次我重新启动设备时,Facebook 和其他应用程序都会向我发布通知,所以有办法做到这一点。也许你应该使用开机/重启广播stackoverflow.com/questions/53847965/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-22
    • 2012-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多