我有现有的应用程序,是能够甚至产生可听通知声音时,该设备有其环体积通过使用Alarm
音频流沉默(假设警报音量不为零)。这在Android 7.1.2听觉通知(Android奥利奥)
工作得很好我的设备升级到奥利奥(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);
任何想法?