Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push Notifications: Android 13 requires POST_NOTIFICATIONS permission #1135

Closed
hermitdemschoenenleben opened this issue Aug 17, 2022 · 18 comments
Labels
Milestone

Comments

@hermitdemschoenenleben
Copy link

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.

@hermitdemschoenenleben
Copy link
Author

I found out that a corresponding issue already exists for local notifications: #1116
Problem is the same, just has to be built in for local notifications as well as for push notifications

@kemalcany
Copy link

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

@hermitdemschoenenleben
Copy link
Author

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

@jadsy2107
Copy link

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 ?

@jadsy2107
Copy link

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

@jadsy2107
Copy link

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)

@joshuavillano
Copy link

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?

@hermitdemschoenenleben
Copy link
Author

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.

@indiebloom
Copy link

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.

@khromov
Copy link

khromov commented Apr 11, 2023

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.

@khromov
Copy link

khromov commented Apr 12, 2023

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

@jcesarmobile
Copy link
Member

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

@ciccilleju
Copy link

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

@jcesarmobile
Copy link
Member

no, it won't, this is a breaking change, so can't be backported.

@ciccilleju
Copy link

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?

@jcesarmobile
Copy link
Member

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.

@ciccilleju
Copy link

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 😀

@ionitron-bot
Copy link

ionitron-bot bot commented May 14, 2023

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.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators May 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants