NotificationCompat.PRIORITY_DEFAULT在较旧的OS版本上不发出声音 [英] NotificationCompat.PRIORITY_DEFAULT doesn't make sound on older OS versions

查看:298
本文介绍了NotificationCompat.PRIORITY_DEFAULT在较旧的OS版本上不发出声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有指定任何声音(资源),我想使用默认声音

I don't specify any sound (resource), I want to use the default sound

在Android 8和9上运行正常

It works fine on Android 8 and 9

但是在Android 4-7上,它会触发没有声音的通知

But on Android 4-7 it triggers notification without sound

如何在所有Android设备上进行相同的行为?

How can I make the same behavior on all Android?

通知生成器:

NotificationCompat.Builder(this, channelId)
    .setSmallIcon(R.drawable.notify_icon
    .setContentTitle(title)
    .setContentText(subtitle)
    .setPriority(if (Prefs.isNotificationSound) NotificationCompat.PRIORITY_DEFAULT else NotificationCompat.PRIORITY_LOW)
    .setCategory(NotificationCompat.CATEGORY_PROMO)
    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
    .setAutoCancel(true)

推荐答案

您是否尝试过使用.setDefaults(Notification.DEFAULT_SOUND)吗?

这篇关于NotificationCompat.PRIORITY_DEFAULT在较旧的OS版本上不发出声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆