问题描述:
Android 8.0的TV系统通知音失效
分析过程:
跟踪触发通知的流程, SystemUI 通知音播放是调用Ringtoneplayer播放类的,这个接收的参数是声音的URI路径,是从 Notificationrecord calculatesound方法里传的
在calculateSound()函数里:
if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
return null;
}
这里会根据系统是否有FEATURE_LEANBACKT框架支持来判断当前设备类型是否是TV设备(因为TV设备有FEATURE_LEANBACKT框架),如果是TV设备,就直接 return null 。最终传给Ringtoneplayer的是null,所以就没有声音
frameworks/base/services/core/java/com/android/server/notification/NotificationRecord.java
private Uri calculateSound() {
178 final Notification n = sbn.getNotification();
179
180 // No notification sounds on tv
181 if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
182 return null; //这里导致
183 }
184
185 Uri sound = mChannel.getSound();
186 if (mPreChannelsNotification && (getChannel().getUserLockedFields()
187 & NotificationChannel.USER_LOCKED_SOUND) == 0) {
188
189 final boolean useDefaultSound = (n.defaults & Notification.DEFAULT_SOUND) != 0;
190 if (useDefaultSound) {
191 sound = Settings.System.DEFAULT_NOTIFICATION_URI;
192 } else {
193 sound = n.sound;
194 }
195 }
196 return sound;
197 }
解决方法:
注释掉return null就可以了
181 if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
182 //return null; //这里导致 ,注释即可
183 }
在Android 8.0的TV系统中,由于在NotificationRecord的calculateSound()函数中,如果检测到设备为TV并具有FEATURE_LEANBACK特性,会返回null导致通知音无法播放。解决方法是注释掉该判断中的return null行,使得通知音正常播放。
3433

被折叠的 条评论
为什么被折叠?



