capacitor-plugins
capacitor-plugins copied to clipboard
Push Notifications: Android 13 requires POST_NOTIFICATIONS permission
Feature Request
Plugin
push-notifications
Description
As Android 13 was released yesterday, I noticed that it requires that the user grants the runtime permission POST_NOTIFICATIONS
before a user may receive push messages. Am I right that the capacitor push-notifications plugin doesn't implement this yet? As far as I know, requestPermissions()
only does something on ios, but not on android.
More Info: https://firebase.google.com/docs/cloud-messaging/android/client#request-permission13
Platform(s)
Android 13
Preferred Solution
requestPermissions()
should ask for POST_NOTIFICATIONS
on Android 13.
I found out that a corresponding issue already exists for local notifications: https://github.com/ionic-team/capacitor-plugins/issues/1116 Problem is the same, just has to be built in for local notifications as well as for push notifications
The link below explains best practices on how new apps (Android 13+) should use this feature (for your reference). The corresponding Capacitor docs for the plugin might need to be updated as well..
https://developer.android.com/develop/ui/views/notifications/notification-permission#new-apps
as a workaround, I created a simple capacitor plugin that can be used for obtaining POST_NOTIFICATIONS permission on android: https://github.com/hermitdemschoenenleben/capacitor-plugin-android-post-notifications-permission
just tried your plugin @hermitdemschoenenleben
error: cannot find symbol @Permission(strings = { Manifest.permission.POST_NOTIFICATIONS }, alias = AndroidPostNotificationsPermissionPlugin.POST_NOTIFICATIONS) ^ symbol: variable POST_NOTIFICATIONS location: class permission
What does this mean I wonder ?
just tried your plugin @hermitdemschoenenleben
error: cannot find symbol @Permission(strings = { Manifest.permission.POST_NOTIFICATIONS }, alias = AndroidPostNotificationsPermissionPlugin.POST_NOTIFICATIONS) ^ symbol: variable POST_NOTIFICATIONS location: class permission
What does this mean I wonder ?
fixed by
compileSdkVersion = 33
in variables.gradle
just tried your plugin @hermitdemschoenenleben error: cannot find symbol @Permission(strings = { Manifest.permission.POST_NOTIFICATIONS }, alias = AndroidPostNotificationsPermissionPlugin.POST_NOTIFICATIONS) ^ symbol: variable POST_NOTIFICATIONS location: class permission What does this mean I wonder ?
fixed by
compileSdkVersion = 33
in variables.gradle
Still doesn't work,
Im running latest Ionic @caoacitor/push-notifications plugin and it doesnt ask for notifications when opening app, however it only asks weirdly on second app open immediately
(preferably should ask after toggle my enable notifications button, like on IOS - not at beginning of app open)
Without this plugin, we are also getting the prompt on second app launch. According to ionic team, they should get it on first app launch. I wonder how this is done?
I think on older SDKs you get it on the first app launch after you've initialized push messages – which is typically the second app launch.
I'm not getting the request for permission until after the first push notification is received while the app is backgrounded. This results in the first push being lost. I have targetSdkVersion = 32.
Having same issue here as @indiebloom, after second launch while app is in background notification permissions prompt shows up, even though I have implemented the actual permission check as a result of the user pushing a button to enable notifications, like this:
let permStatus = await PushNotifications.checkPermissions();
if (permStatus.receive === 'prompt') {
permStatus = await PushNotifications.requestPermissions();
}
I would like for it to ask for permissions when calling PushNotifications.requestPermissions();
, not after the first notification has already arrived (and gotten lost). I am targeting SDK 32.
I got help in the Capacitor discord to install the Capacitor 5 beta and that made notifications work! Here is some more info: https://discord.com/channels/520266681499779082/908091931295375380/1095795167635701800
this was fixed in @capacitor/push-notifications 5 alpha 1, can be installed using capacitor 5 and next
npm tag
check the capacitor 5 upgrade guide (it's still in beta) https://capacitorjs.com/docs/next/updating/5-0
tried to update to the beta version (both capacitor and the capacitor plugin) and it actually works again and asks for permission.
I'd like to know if they will fix it in capacitor 4, because i dont want to rush updating my apps
no, it won't, this is a breaking change, so can't be backported.
no, it won't, this is a breaking change, so can't be backported.
I see. Well, I noticed that using target 32 instead of 33 seems to be fine at the moment, am I wrong?
No, you are not wrong, if you target SDK 32 then you don't need to request the push notification permission yourself, but you can't control when it will be requested, it's usually requested when you or a plugin creates a notification channel, but in some devices it can happen on next app launch after a channel was created.
Main reason of Capacitor 5 to exist is to properly target SDK 33. It will support same iOS and Android versions Capacitor 4 supports, so should be an easy update.
No, you are not wrong, if you target SDK 32 then you don't need to request the push notification permission yourself, but you can't control when it will be requested, it's usually requested when you or a plugin creates a notification channel, but in some devices it can happen on next app launch after a channel was created.
Main reason of Capacitor 5 to exist is to properly target SDK 33. It will support same iOS and Android versions Capacitor 4 supports, so should be an easy update.
Thank you so much for your excellent explanation. You are a boss 😀
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.