Is it possible to make an Android device vibrate when receiving notifications in the background with Firebase Cloud Messaging? From the Syntax Reference I have seen and tested that sound is supported, but no info on vibration. Or is it somehow possible to provide a customized implementation for this notification where I would directly set the vibration?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You should mark yourself as a correct answer.
On a sidenote, if you do send a Notification and a Data payload, use
"notification":{
"sound":"default"
}
This will play the sound when the application is in background and the device is set to sound, and it will play a vibration if the device is set to vibrate.
However, as far as customization goes I think you need to use the Data Payload only if you want to customize the vibration pattern for example.
回答2:
From what I have tested the format of the FCM Notification message seems to be quite rigid, so for customized notifications, the solution seems to be:
- Making sure that the payload of the JSON message being sent downstream contains the
data
parameter but doesn't contain thenotification
parameter (Sources: Message JSON Syntax, FCM Message Types) - Creating the Notification in the implementation of the overridden
onMessageReceived(RemoteMessage remoteMessage)
from the application'sFirebaseMessagingService
(Example)
回答3:
array("title"=>"hello","body" =>"hello world",'sound' => 'default')