且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android Firebase 通知没有自定义声音

更新时间:2023-02-26 20:56:45

终于找到了解决方案.对于 Android 8.0 及更高版本,需要在您的应用中创建通知通道:

Finally I found the solution. For Android 8.0 and higher it's necessary to create a notification channel in your App:

NotificationChannel channel = new NotificationChannel('my_id', name, importance);

(更多信息:https://developer.android.com/training/notify-user/channels#java)

那么当你发送通知时:

var registrationToken = 'xxxxxx';

var message = {

    notification: {
      title: 'my title',
      body: 'my body',
    },
    android: {
      ttl: 3600 * 1000,
      notification: {
        color: '#ff0000',
        sound: 'mysound.mp3',
        channel_id: 'my_id' // important to get custom sound
      }
    }, 
    token: registrationToken

};