Trying to get Android 13 permission to send local notifications

635 views Asked by At

I'm working with this Cordova plugin https://github.com/bhandaribhumin/cordova-plugin-local-notification-12 which has been working great! But now in Android 13, it never asks the user's permission to send local notifications - so none can be sent. The developer suggests using setdummynotification() in the plugin but that doesn't do anything.

Does anybody have any advice?

I've looked at the code for setdummynotification() and not sure what's wrong. Is there another Cordova local notifications plugin that is working on Android 13? I saw a suggestion to send the user to the Android system settings to manually enable notifications but that's a horrible solution!

Thanks for any help!

  • Jon -
3

There are 3 answers

0
Eric On

You could take a look at https://github.com/NeoLSN/cordova-plugin-android-permissions

This plugin is designed to support Android's new permissions checking mechanism, and has been updated to include the newest permissions added in Android 13.

Check the permissions then if needed, request it

 var permissions = cordova.plugins.permissions;
 permissions.checkPermission(permission, successCallback, errorCallback);
 permissions.requestPermission(permission, successCallback, errorCallback);
0
Jon Schlossberg On

Yes, that's it! Simple with that plugin:

 permissions.requestPermission(permissions.POST_NOTIFICATIONS, successPermissionNotification, errorPermissionNotification);

Thanks!

0
Klaassiek On

I wrote a plugin that targets Android 13 (API Level 33) and above. This plugin implements the new runtime permission needed to show notifications. https://www.npmjs.com/package/cordova-plugin-notifications-permission

This includes a rationale dialog. In this dialog you can explain to the user why the permission is needed. First time around the plugin just asks for permission, second time around the plugin shows the rationale behind the request to the user. If the user clicks "OK", the plugin asks for permission again.

Sample usage:

permissionPlugin.maybeAskPermission(
    /* Callback that returns the status. */
    function(status){
        /* Read the permission status. Can be granted or denied */
    }, 
    /* rationale dialog settings: an object with the options for texts and theme. */
    {
        rationaleMsg, /* message on the rationale notification dialog */
        rationaleOkButton, /* text on the rationale OK button */
        rationaleCancelButton, /* text on the rationale Cancel button */
        theme /* theme to use to style the rationale dialog.*/
    }
);