Firebase 云消息传递通知振动

Firebase Cloud Messaging Notification Vibration

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

据我测试,FCM Notification消息的格式似乎很死板,所以对于自定义通知,解决方案似乎是:

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

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

旁注,如果您发送通知和数据负载,请使用

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

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

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

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