An Android O app can set a custom sound on a NotificationChannel using an app sound resource:
NotificationChannel channel = new NotificationChannel(channelId, name, importance);
Uri uri = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.customSound);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.build();
channel.setSound(uri, audioAttributes);
Now in the system settings, the user can reconfigure the NotificationChannel, picking a different sound from the system's sound resources.
Problem: That list of sounds does not include the app's own sound resources, so the user can never revert to the app's custom sound resource after changing it.
Q. How can the app let the user restore the app's custom sound resource? Does the app have to copy the sound file to a shared directory (and make that work)?
Channels are one-shoot, after the creation the app can't modify them. So you could delete the channel and create it again or you can copy your sound resource file in the public directory to let the user select it when he adjusts the channel settings.
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