Support Android 13 run time notification permission
Problem description
Android 13 is changing the requirement for notification permission to run-time grant by user instead of auto grant. Refer this link.
Due to this change for apps that are not changing target SDK version to 33 have no control over permission rationale dialog and it is shown to user as soon as a notification channel is created or a notification is posted by app. With using LeakCanary, notification channel is created upon finding first leak and hence causes a permission dialog to be shown. Refer screenshot displayed in third screen at this link. So app has no control on when this permission dialog shows up. This affects the user behavior and there isn't any work around.
Expecting a way to control the leak canary notifications to be generated only after a certain point after notification permission is granted.
Potential solutions
There can be couple of solutions possible.
- Allow app to control enablement of notifications for LeakCanary. So App can control run time permission before any notification is shown.
- LeakCanary can check if notification permission granted for an app and only then show leak notifications.
Additional information
Not specific with app but can be checked with any app that targets lower than 33 API and includes leak canary. Refer to a comment for related change https://github.com/square/leakcanary/pull/2395#issuecomment-1175168639
Thx. The linked PR would help with disabling / delaying notifications until the permission is granted.
However, I'm not clear what the default behavior when you don't set anything should be.
One of the drivers here is to allow apps to control when we should attempt to show notifications, for scenarios where we don't want that permission to show up.
As a first step, we'll add a control to allow disabling all LeakCanary notifications.
@pyricau I still want the notifications, but I want to be the one to request for the permission and Leak Canary should show notifications after that. Is that possible at the moment?
I believe yes, just set LeakCanary.config.showNotifications to false (=> won't show notifications) and then set it to true once you've gotten the permission.