No custom sound with Android Firebase Notification

后端 未结 6 1530
轮回少年
轮回少年 2021-01-17 10:39

I am using Firebase push notifications in my Android App. I can send correctly notification with custom icon, but I have not managed to play my custom sound. I always get th

6条回答
  •  清酒与你
    2021-01-17 11:14

    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);
    

    (more info: https://developer.android.com/training/notify-user/channels#java)

    Then when you send the notification:

    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
    
    };
    

提交回复
热议问题