Jer*_*101 5 audio android android-notifications android-8.0-oreo
Android O 应用可以使用应用声音资源在 NotificationChannel 上设置自定义声音:
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);
Run Code Online (Sandbox Code Playgroud)
现在在系统设置中,用户可以重新配置 NotificationChannel,从系统的声音资源中选择不同的声音。
问题:该声音列表不包括应用程序自己的声音资源,因此用户在更改后永远无法恢复到应用程序的自定义声音资源。
Q. APP如何让用户恢复APP的自定义声音资源?应用程序是否必须将声音文件复制到共享目录(并使其工作)?
频道是一次性的,创建后应用程序无法修改它们。因此,您可以删除该通道并重新创建它,也可以将您的声音资源文件复制到公共目录中,以便用户在调整通道设置时选择它。
| 归档时间: |
|
| 查看次数: |
586 次 |
| 最近记录: |