Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let the user revert to an app-custom sound?

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

like image 840
Jerry101 Avatar asked Nov 08 '22 18:11

Jerry101


1 Answers

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.

like image 189
greywolf82 Avatar answered Nov 15 '22 08:11

greywolf82