Search code examples
androidforeground-serviceandroid-13android-notification.mediastyle

Update MediaStyle notification of a foreground service without POST_NOTIFICATIONS permission via NotificationManager.notify in Android 13


My app targets API 33 (Android 13), and runs a foreground service to play online music.

Once the notification is started via startForeground(notification_Id, notification), I can update the notification via notificationManager.notify(notification_Id, notification). However, Android Studio tells me that the android.permission.POST_NOTIFICATIONS permission is missing.

Even though I include that permission in the AndroidManifest, I don't need to ask the user to grant the permission to update the notification.

Is this method of updating the notification is valid or is it a security hole? Obviously the method works, but I have not found any reference in the documentation of Android 13+


Solution

  • Even though I include that permission in the AndroidManifest, I don't need to ask the user to grant the permission to update the notification.

    Can anyone confirm if this method of updating the notification is valid or is it a security hole? Obviously the method works but I have not found any reference in the documentation of Android 13+

    That's fine. No security hole. There are some exemptions that do not require the POST_NOTIFICATIONS permission. According to the official documentation, notifications related to media sessions are exempt from this behavior change. MediaStyle uses media session to build up the notification.