Android 9.0 NotificationManager.notify() throwing java.lang.SecurityException

前端 未结 2 2084
萌比男神i
萌比男神i 2021-02-09 05:50

I have been unable to reproduce this problem myself, but so far 5 users have reported it. I did recently publish an app update that changed the target SDK from 27 to 28 which I

2条回答
  •  灰色年华
    2021-02-09 06:30

    I had this issue. Turns out that the creation of the notification channel was at fault.

    Wrong way:

    val notifictionChannel = NotificationChannel(...)
    notificationChannel.setSound(
        RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION),
        AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build()
    )
    
    notificationManager.createNotificationChannel(notificationChannel)
    

    Right way:

    ...
    notificationChannel.setSound(
        Settings.System.DEFAULT_NOTIFICATION_URI,
        AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build()
    )
    ...
    

提交回复
热议问题