我的应用程序要求是在玩家状态更改时更新媒体样式通知.之前完美地工作,触发并显示mediaSession的新媒体类型通知,没有声音或振动.
现在问题:在根据Android O要求构建通知渠道时,我使用以下代码创建通知渠道.然后令人讨厌的问题是,每次媒体会话改变时,每个通知都会更新,在Android O中现在播放通知声音.
我想为每个新通知禁用声音,如果我没有设置声音,则默认声音触发,在两个字段中传入null都不起作用.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(
NOTIFICATION_CHANNEL_ID,
"SimpleBakingApp Media Notification",
NotificationManager.IMPORTANCE_LOW
);
// Configure the notification channel.
notificationChannel.setDescription("Channel description");
notificationChannel.setSound(null,null); // <-- Is there a way to disable sound? null doesn't work
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.enableVibration(false);
mNotificationManager.createNotificationChannel(notificationChannel);
}
Run Code Online (Sandbox Code Playgroud)
额外的信息,可能是相关的
我的showNotification()(构建通知的方法)触发Player.EventListener回调中的玩家状态更改,我正在使用ExoPlayer v2.
你在寻找什么setOnlyAlertOnce(boolean).
当您创建通知时,true如果您只希望第一次显示该通知(而不是对同一通知的后续更新)来触发声音和/或振动,则可以将此设置为.
| 归档时间: |
|
| 查看次数: |
5297 次 |
| 最近记录: |