I try to implement feature when notification arrives, the phone should vibrate and play some kind of ringing sound.
How ever, i could only play phone's default notification sound.
The versions I'm using:
"react": "16.6.0-alpha.8af6728",
"react-native": "0.57.8",
"react-native-firebase": "^5.2.1",
The code:
First I create the channel
const channel = new firebase.notifications.Android.Channel(
'my_channel_id',
'My channel',
firebase.notifications.Android.Importance.Max
)
.setDescription('My Notif')
.setSound("mysound.mp3")
.setVibrationPattern([400, 800, 600, 800, 800, 800, 1000])
.setLockScreenVisibility(firebase.notifications.Android.Visibility.Public)
this.channel.enableVibration(true);
firebase.notifications().android.createChannel(channel);
Then later I create the notificaiton
const notification = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle('Some notification')
.setBody('Some body')
notification.android.setSmallIcon('ic_launcher');
notification.android.setLargeIcon('ic_launcher');
notification.android.setChannelId('my_channel_id');
notification.android.addAction(new firebase.notifications.Android.Action("answer", "ic_launcher", "Open"))
notification.android.setColorized(true)
notification.android.setColor('#00a8ff')
notification.android.setOnlyAlertOnce(true)
notification.android.setPriority(firebase.notifications.Android.Priority.Max)
notification.android.setVibrate([400, 800, 600, 800, 800, 800, 1000]);
firebase.notifications().displayNotification(notification);
Notification is displayed with default sound. The mp3 file is located at /android/app/src/main/res/raw/. It plays always the default notification "bling" sound.
No errors are shown in console.
adb logcat says something like this but I'm not sure are they related to this:
02-22 21:20:30.848 4916 4916 D EdgeLightingManager: showForNotification : isInteractive=true, isHeadUp=true, color=0, sbn = StatusBarNotification(pkg=com.my user=UserHandle{0} id=788267878 tag=null key=0|com.my|788267878|null|10188: Notification(channel=my_channel_id pri=2 contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff00a8ff actions=1 number=0 vis=PRIVATE semFlags=0x0 semPriority=0 semMissedCount=0))
These settings are in AndroidManifest.xml
<uses-permission-sdk-23 android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.VIBRATE" />
I have checked phone settings, all sounds are on and vibrations enabled.
So, should my code work? Thank you!
btw, I hear no sound in iOS neither but there I'm not using firebase :)
For about the vibration, this works for me
.android.setVibrate([1000, 1000])
.android.setDefaults([firebase.notifications.Android.Defaults.Vibrate])
Your issue may be that you are not re-assigning the notification object. For example:
notification = notification.android.setVibrate([300]);
Otherwise you are just setting it on a new object that is never used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With