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 14 SCHEDULE_EXACT_ALARM permission required. Permission is now defaulted to false even with manifest tag. #15

Open
BradCB opened this issue Nov 13, 2023 · 6 comments

Comments

@BradCB
Copy link

BradCB commented Nov 13, 2023

Android 14+ schedule notifications will not fire unless the permission is explicitly allowed.
More info here: https://developer.android.com/training/scheduling/alarms#using-schedule-exact-permission.

It's not really an issue with this plugin. It's just a new requirement for Android 14+ to get the permission explicitly before any scheduling is permitted.

@BradCB BradCB changed the title Android 14 SCHEDULE_EXACT_ALARM permission. Android 14 SCHEDULE_EXACT_ALARM permission required. Permission is now defaulted to false even with manifest tag. Nov 14, 2023
@ppetree
Copy link

ppetree commented Feb 9, 2024

Yeah, this needs some code to resolve this for us developers.

@danemco
Copy link

danemco commented Mar 22, 2024

Any update on this?

@ppetree
Copy link

ppetree commented Mar 26, 2024

So, the best I have managed to come up with is to use the mixon plugin for notifications, use the @havesource push notification plugin to create the channel for custom sounds and then there's another plugin that handles just the permissions on Android 14. I still have to test it all but I know mixon works so far and the channels I'm using for custom push sounds so everything should work. Be next week before I can get back to this one.

@jondspa
Copy link

jondspa commented Apr 11, 2024

Here's my solution. I added some lines in dummyNotifications() to call the new Alarms and Reminders settings page. The user enables a toggle there and then notifications work on Android 14.

I'm not much of a Java programmer but this works.

In platforms/android/app/src/main/java/de/appplant/cordova/plugin/localnotification/LocalNotification.java
in the function dummyNotifications.

Add this near the top:
import android.app.AlarmManager;

After this section:

  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)
    {
        int importance = NotificationManager.IMPORTANCE_HIGH;
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance);
        assert mNotificationManager != null;
        mBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
        mNotificationManager.createNotificationChannel(notificationChannel);
    }

Add these lines:

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
            // check and set alarms
            AlarmManager mAlarmManager = context.getSystemService(AlarmManager.class);
            if (mAlarmManager.canScheduleExactAlarms() == false) {
                    Intent intent = new Intent(android.provider.Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM);
                    intent.setData(Uri.fromParts("package", context.getPackageName(), null));
                    cordova.startActivityForResult(this, intent, REQUEST_PERMISSIONS_CALL);
           }
   }

makoto-ikarashi added a commit to makoto-ikarashi/cordova-plugin-local-notification-12 that referenced this issue Apr 22, 2024
makoto-ikarashi added a commit to makoto-ikarashi/cordova-plugin-local-notification-12 that referenced this issue Apr 22, 2024
@Afnan0711
Copy link

Any update on this?

@marco-hd
Copy link
Contributor

For me it works without this fix but I've got a warning from Play Console.

Any idea how to get rid of this?

issue

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