【发布时间】:2017-09-17 20:39:41
【问题描述】:
我有以下代码,但每次我只听到默认的 android 声音。
// create channel
NotificationChannel channel = new NotificationChannel(ANDROID_CHANNEL_ID,
ANDROID_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
// Sets whether notifications posted to this channel should display notification lights
channel.enableLights(true);
// Sets whether notification posted to this channel should vibrate.
channel.enableVibration(true);
// Sets the notification light color for notifications posted to this channel
channel.setLightColor(Color.GREEN);
// Sets whether notifications posted to this channel appear on the lockscreen or not
//channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
Uri uri = Uri.parse("android.resource://"+this.getPackageName()+"/" + R.raw.aperturaabductores);
AudioAttributes att = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
.build();
channel.setSound(uri,att);
【问题讨论】:
-
经过测试。在模拟器中工作。
-
在我的模拟器和设备中也不起作用。你在 Android 8 上测试过吗?请注意,我想加载自定义声音。
-
我用我的自定义声音做了,我知道它是 8。提供声音,我会尝试的。
-
对我来说不同的是在频道上设置了android oreo的声音文件。
标签: android android-notifications android-8.0-oreo