Channel custom notification sound issue playing (Android 11)

Viewed 794

I create custom channels for the notifications in my app. with custom sounds that the user can change within the app, On Android 11 notification sounds stopped working.

The path to the folder where I save and target the sounds is like this: /storage/emulated/0/Android/data/com.appName.app/files

*The path to the app folder is generated automaticlly via react-native-fs (ExternalDirectoryPath)

I am able to change the audio files and have validated they exist. This method has been working so far, untill Android 11 users don't get the notification sound working with this method.

Channel creation:

public void createChannel(String channelID, String channelName, String audioPath) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        // Audio Attribute
        // audioPath = "/storage/emulated/0/Android/data/com.appName.app/files/example.wav"
        Uri soundUri = Uri.parse(audioPath);
        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .build();
        // Channel settings
        NotificationChannel notificationChannel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH);
        notificationChannel.setDescription("Text here");
        notificationChannel.setSound(soundUri, audioAttributes);
        notificationChannel.setShowBadge(true);
        notificationChannel.enableVibration(true);

        NotificationManager manager = reactContext.getSystemService(NotificationManager.class);
        manager.createNotificationChannel(notificationChannel);
    }
}

How can I fix this on Android 11, what is the issue? I want to be able to play the sounds from the external app data folder.

0 Answers
Related