【发布时间】:2017-09-10 05:04:18
【问题描述】:
我有一个现有的应用程序,即使设备使用Alarm 音频流将其铃声静音(假设警报音量不为零),它也能够产生可听见的通知声音)。这在 Android 7.1.2 上运行良好
将我的设备升级到 Oreo 后 (8.0.0),通知是不再可听到,除非铃声音量非零。 应用未更改。
所以我尝试解决这个问题是针对 Oreo (SDK 26) API 重新编译并包含新的 NotificationChannel 内容,只是为了看看是否有帮助,但它没有。
请注意,此代码是在 Service 中执行的。
这是一段代码摘录:
int importance = NotificationManager.IMPORTANCE_MAX;
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
NotificationChannel mChannel = new NotificationChannel("channel1", "Alarms", importance);
mChannel.setDescription("Alarms that alert you immediately");
mChannel.enableLights(true);
mChannel.enableVibration(true);
mChannel.setSound(defaultSoundUri,
new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ALARM)
.setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build()
);
notificationManager.createNotificationChannel(mChannel);
Notification.Builder notificationBuilder = new Notification.Builder(this,"channel1")
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle("Alarm Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri, new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ALARM)
.setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build())
.setContentIntent(pendingIntent)
.setCategory(Notification.CATEGORY_ALARM)
.setPriority(Notification.PRIORITY_MAX);
Notification n = notificationBuilder.build();
n.flags = n.flags | Notification.FLAG_INSISTENT;
notificationManager.notify(0 /* ID of notification */, n);
有什么想法吗?
【问题讨论】:
标签: android android-notifications alarm android-8.0-oreo