cordova-plugin-local-notifications
cordova-plugin-local-notifications copied to clipboard
Android 12+ notification permissions not requested and showing as blocked
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 ([email protected]) - 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
- ...
- ...
- ...
- ....
Context
What were you trying to do?
Debug logs
Include iOS / Android logs
- ios XCode logs
- Android: $ adb logcat
@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?
@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.
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.
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.
@xallysie when using https://github.com/NeoLSN/cordova-plugin-android-permissions what permissions are you asking for?
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
@orhan-swe I think you need to set this flag to prevent restart: <preference name="AndroidLaunchMode" value="singleInstance"/>
as told in the NotificationTrampolineActivity comment
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?
@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.
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