Android Question Custom Notification Ringtone In Firebase Notification

hongbii khaw

Member
Licensed User
Longtime User
Hi all,
I'm using the Firebase Push Notification and NB6 mentioned inhttps://www.b4x.com/android/forum/threads/nb6-notifications-builder-class-2018.91819/#content
I implement the code in the fm_MessageArrived in FirebaseMessaging Service module.https://www.b4x.com/android/forum/t...s-firebase-cloud-messaging-fcm.67716/#content
B4X:
Dim rp As RuntimePermissions
        Dim folder As String = rp.GetSafeDirDefaultExternal("shared")
        Dim FileName As String = ringtone
        'copy the file to the shared folder
        File.Copy(File.DirAssets, FileName, folder, FileName)
        Dim n As NB6
        n.Initialize("Channel1", Application.LabelName, "HIGH")
        n.SmallIcon(LoadBitmapResize(File.DirAssets, "icon.png", 32dip, 32dip, True))
        'disable the default sound
        n.SetDefaults(False, True, True)
        'set custom sound
        n.CustomSound(CreateFileProviderUri(folder, FileName))
        Dim Notification As Notification = n.Build(Title, Body, "", Me)
        Notification.Notify(3)
The custom ringtone rang successfully when the app is in foreground but becomes phone's default ringtone when the app is closed.
*Before setting the targetSDK to 26, the custom notification ringtone is work probably for both situations.
The ringtone name is sent in both data and notification tray from server side:https://firebase.google.com/docs/cloud-messaging/concept-options
B4X:
 var notification = new
            {
                to = key,
                data = new
                {
                    title = _title,
                    body = _message,
                    sound = ringtone,
                    device = deviceSerial,
                    mode = mode1,
                },
                notification = new
                {
                    title = _title,
                    body = _message,
                    sound = ringtone,  
                    device = deviceSerial,
                    mode = mode1,
                },
                priority = 10
            };
Is that anything I can do to let the notification rang with custom ringtone even the app is closed by the user?
 
Top