我有現有的應用程序,是能夠甚至產生可聽通知聲音時,該設備有其環體積通過使用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);
任何想法?