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

Show notification permission request prompt on Android T+ #731

Merged

Conversation

marto55555
Copy link
Contributor

This makes notifications work again on Android 13 (and newer) by declaring an activity for showing the notification permission request prompt.

Potentially fixes #730

@google-cla
Copy link

google-cla bot commented Nov 23, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@marto55555 marto55555 closed this Nov 23, 2022
@marto55555 marto55555 reopened this Nov 23, 2022
@mvano
Copy link

mvano commented Dec 9, 2022

Thanks Martin!

@marto55555 marto55555 requested a review from PEConn December 9, 2022 19:37
@PEConn PEConn merged commit d51b6be into GoogleChromeLabs:main Dec 12, 2022
@tnfly
Copy link

tnfly commented Jan 31, 2023

I've patched my npm install (v 1.18.1) with these updates to allow notifications on Android 13+. Should I be getting a prompt on the device to enable notifications when the app installs? Currently, I'm getting the effect of notifications defaulting to disabled and not providing an option to the user to enable them.

@marto55555
Copy link
Contributor Author

@alexzlaten The prompt should appear when calling Notification.requestPermission() with a user action (e.g. button tap).

@tnfly
Copy link

tnfly commented Jan 31, 2023

@marto55555 Thanks for that. So the call must be from user action? I find if I call Notification.requestPermission() from the console it is immediately denied without a prompt.

@marto55555
Copy link
Contributor Author

marto55555 commented Jan 31, 2023

@alexzlaten Actually, I was wrong - a user action is not needed, sorry. Calling it directly from the console worked for me.

Have you tried uninstalling the app so that it resets Android's requested permissions history? Or maybe something went wrong with the patching.

@tnfly
Copy link

tnfly commented Jan 31, 2023

@marto55555 I have uninstalled/reinstalled several times and cleared site settings in chrome. I even enabled notifications for the app, uninstalled it, and reinstalled. Notification were disabled and Notification.requestPermission() returned "denied". The patch seems pretty simple, but perhaps I did something incorrectly. My version has FeatureManager.js rather than FeatureManager.ts. Maybe it's time for me to checkout the project and make a build with your changes rather than patching? That will be a new adventure for me.

@tnfly
Copy link

tnfly commented Jan 31, 2023

@marto55555 Success! I was targeting SDK 31 and it needed 33 for this feature. I uploaded a test to the play store and the notification permissions were requested by the OS kicked off by Onesignal's library. Thank you for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android 13 Notifications - No prompt shown
5 participants