【问题标题】:Firebase Cloud Messaging Notification VibrationFirebase 云消息通知振动
【发布时间】:2016-11-21 15:02:18
【问题描述】:

是否可以在使用 Firebase 云消息传递在后台接收通知时使 Android 设备振动?从Syntax Reference 我已经看到并测试了支持声音,但没有关于振动的信息。或者是否有可能为此通知提供自定义实现,我可以直接设置振动?

【问题讨论】:

标签: android push-notification firebase-cloud-messaging


【解决方案1】:

您应该将自己标记为正确答案。

在旁注中,如果您确实发送了通知和数据负载,请使用

"notification":{
    "sound":"default"
}

这将在应用程序处于后台并且设备设置为声音时播放声音,如果设备设置为振动,它将播放振动。

但是,就自定义而言,我认为只有在您想要自定义振动模式时才需要使用数据负载。

【讨论】:

    【解决方案2】:

    从我测试的 FCM 通知消息的格式来看,似乎比较死板,所以对于自定义通知,解决方案似乎是:

    1. 确保向下游发送的 JSON 消息的负载包含 data 参数,但包含 notification 参数(来源:Message JSON SyntaxFCM Message Types
    2. 在应用程序的FirebaseMessagingService (Example) 覆盖的onMessageReceived(RemoteMessage remoteMessage) 的实现中创建通知

    【讨论】:

    • 这只是通知声音还是振动
    • 如果我在 iOS 和 Android 上使用相同的消息会怎样?我无法避免消息中的notification 对象。添加sound 字段不会在后台振动...
    【解决方案3】:

    array("title"=>"hello","body" =>"hello world",'sound' => 'default')

    【讨论】:

    • 函数 send_notification($tokens,$notification) { $url = 'fcm.googleapis.com/fcm/send'; $priority="高"; $fields = array('registration_ids' => $tokens, 'notification' => $notification);
    猜你喜欢
    • 2020-06-19
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    • 2016-12-25
    • 2018-03-13
    • 1970-01-01
    相关资源
    最近更新 更多