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

Android 12+ notification permissions not requested and showing as blocked #2004

Open
alexp25 opened this issue Feb 19, 2023 · 10 comments
Open

Comments

@alexp25
Copy link

alexp25 commented Feb 19, 2023

The requestPermission function does not seem to do anything on Android 12+. When I check the native permissions, notifications show as blocked. As this repo is outdated and doesn't even work on Android 12+, I'm using a fork (https://github.com/fquirin/cordova-plugin-local-notifications) which works fine, except for requesting notification permissions popup.

Your Environment

  • Plugin version: https://github.com/fquirin/cordova-plugin-local-notifications
  • Platform: Android
  • OS version: 13
  • Device manufacturer / model: Samsung
  • Cordova version (cordova -v): 10.0.0 (cordova-lib@10.1.0)
  • Cordova platform version (cordova platform ls): android 11.0.0
  • Plugin config
  • Ionic Version (if using Ionic) 6.20.1

Expected Behavior

The requestPermission function should trigger the native popup to allow notifications.

Actual Behavior

The requestPermission function does not seem to do anything.

Steps to Reproduce

Reproduce this issue; include code to reproduce, if relevant

  1. ...
  2. ...
  3. ...
  4. ....

Context

What were you trying to do?

Debug logs

Include iOS / Android logs

  • ios XCode logs
  • Android: $ adb logcat
@willmero
Copy link

@alexp25 I'm having the same issue here with my app not being able to request permissions initially. Did you end up getting this to work? Or how did you end up allowing a new user to grant permissions to push within your app?

@cgutierrez365
Copy link

cgutierrez365 commented Jul 25, 2023

@alexp25 I'm having the same issue here with my app not being able to request permissions initially. Did you end up getting this to work? Or how did you end up allowing a new user to grant permissions to push within your app?

I also was unable to get requestPermission working on Android 13. Besides that, every time I call the schedule function the app crashes. Instead I am using this fork (https://www.npmjs.com/package/cordova-plugin-local-notification-12) which fixes the problem of the schedule function crashing on Android 13. It also has a function called setDummyNotifications which triggers the notification permissions popup.

Update 07/26/23: I realized that branch alexp25 suggested (i.e. fquirin/cordova-plugin-local-notifications) also contains some of the fixes from cordova-plugin-local-notification-12. It also appears to work on my end.

@alexp25
Copy link
Author

alexp25 commented Jul 31, 2023

I ended up using another plugin (https://github.com/NeoLSN/cordova-plugin-android-permissions) for requesting notification permissions on Android 12+ and the fork for the actual notifications. Haven't tried the suggested alternative yet.
Note: This only works in the release build.

@xallysie
Copy link

I did something similar to @alexp25 - used the fix from https://github.com/fquirin/cordova-plugin-local-notifications and the android permissions plugin from https://github.com/NeoLSN/cordova-plugin-android-permissions to request notification permissions. This works!

...unfortunately, Android 14 (API 34) breaks it again because it now blocks permissions for SCHEDULE_EXACT_ALARM by default. I tried enabling it using the android permissions plugin but it doesn't seem to work.

@orhan-swe
Copy link

@xallysie when using https://github.com/NeoLSN/cordova-plugin-android-permissions what permissions are you asking for?

@orhan-swe
Copy link

It seems all notifications are needed:

var list = [
            permissions.POST_NOTIFICATIONS,
            permissions.ACCESS_NOTIFICATION_POLICY,
            permissions.RECEIVE_BOOT_COMPLETED,
            permissions.WAKE_LOCK,
            permissions.POST_NOTIFICATIONS,
            permissions.SCHEDULE_EXACT_ALARM
        ];
        permissions.hasPermission(list, function( status ){
..

This works, though on clicking the notification the app restarts

@plchampigny
Copy link

@orhan-swe I think you need to set this flag to prevent restart: <preference name="AndroidLaunchMode" value="singleInstance"/> as told in the NotificationTrampolineActivity comment

@alexp25
Copy link
Author

alexp25 commented Feb 2, 2024

I just received the following warning in Play Console when I submitted a new update:
Your app schedules exact alarms without checking whether the SCHEDULE_EXACT_ALARM permission has been granted. This is causing your app to crash for users on Android 14 because the permission is no longer granted by default.
However, I couldn't detect any issues with notifications while testing on my device.
What exactly is SCHEDULE_EXACT_ALARM supposed to break?

@xallysie
Copy link

xallysie commented Feb 3, 2024

@orhan-swe Sorry it took me a while to respond. All of the functions in your list are included in my AndroidManifest, and only two are not enabled by default (POST_NOTIFICATIONS and SCHEDULE_EXACT_ALARMS). Here is the code I use to request the POST_NOTIFICATIONS permission, which works for android 14:

function permerrorCallback() {
                        console.warn('You have not granted this app permission to receive notifications. Please navigate to Settings > App Info and toggle notifications for this app.');
                    };
function permsuccessCallback( status ) {
                        if( !status.hasPermission ) permerrorCallback();
                    };
permissions.requestPermission(permissions.POST_NOTIFICATIONS, permsuccessCallback, permerrorCallback);

And this is the code I use to request the SCHEDULE_EXACT_ALARM permission, which does nothing:

function permerrorCallback() {
                        console.warn('You have not granted this app permission to receive notifications. Please navigate to Settings > App Info and toggle notifications for this app.');
                    };
function permsuccessCallback( status ) {
                        if( !status.hasPermission ) permerrorCallback();
                    };
permissions.requestPermission(permissions.SCHEDULE_EXACT_ALARM, permsuccessCallback, permerrorCallback);

Not exactly sure why. Both use the plugin created NeoLSN.

@xallysie
Copy link

quick update for anyone following this issue:

I made a small plugin that addresses the SCHEDULE_EXACT_ALARM permissions issue for Android 14+.

https://github.com/xallysie/cordova-plugin-android14-schedule-exact-alarm
https://www.npmjs.com/package/cordova-plugin-android14-schedule-exact-alarm?activeTab=readme

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

No branches or pull requests

6 participants