我们已经为运行在Oreo及以上版本的设备创建了通知渠道,该渠道使用位于我们的
我们确认卸载/重新安装或清除应用数据可以解决此问题。但是,为了让所有人都能再次正常收到通知声音而无需重新安装,我们需要实质上删除并重新创建这些通知渠道。
我们如下创建通知渠道:
我核实了文件仍存在于
/res/raw
文件夹中的自定义通知音。最近,当用户升级我们的应用时,通知声音突然停止工作,并且通知仅会振动设备。我们确认卸载/重新安装或清除应用数据可以解决此问题。但是,为了让所有人都能再次正常收到通知声音而无需重新安装,我们需要实质上删除并重新创建这些通知渠道。
我们如下创建通知渠道:
fun initNotificationChannel(channel: PSSNotificationChannel) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val id = channel.id
val name = context.getString(channel.nameResId)
val importance = channel.importance
val channel = NotificationChannel(id, name, importance)
...
// Default sound
val soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
context.applicationContext.packageName + "/" + R.raw.notification)
val audioAttributes = AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build()
channel.setSound(soundUri, audioAttributes)
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?
notificationManager?.createNotificationChannel(channel)
}
}
我核实了文件仍存在于
/res/raw
。导致这个问题的提交只是在/res
文件夹中添加/修改了一些文件。
MediaPlayer: Couldn't open android.resource://<appname>/2131099651: java.io.FileNotFoundException
)实际上是什么将推送中的通道ID映射到声音URI? - efeder