Plugin.LocalNotification: Android.Util.AndroidException - java.lang.SecurityException

Not sure if this is an issue on our end, maybe some missing configuration but having an issue on a Pixel 7 Pro running android OS 14:

java.lang.SecurityException: Caller ###### needs to hold android.permission.SCHEDULE_EXACT_ALARM or android.permission.USE_EXACT_ALARM to set exact alarms.

We already have one of these permissions in our app i.e. <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> and my understanding is only certain apps such as calendar apps should be using the permission USE_EXACT_ALARM so not sure why we are having the issue, its crashing the app when trying to set alarms and possibly on this call: SetExactAndAllowWhileIdle within NotificationServiceImpl.ShowLater (Plugin.LocalNotification.NotificationRequest request)

The fill stack trace is:

JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args)
JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
AlarmManager.SetExactAndAllowWhileIdle (Android.App.AlarmType type, System.Int64 triggerAtMillis, Android.App.PendingIntent operation)
NotificationServiceImpl.ShowLater (Plugin.LocalNotification.NotificationRequest request)
NotificationServiceImpl.Show (Plugin.LocalNotification.NotificationRequest request)
INotificationScheduleService.ScheduleAlarmsAsync (XamApp.Models.Customer customer, XamApp.Models.CustomerOptions customerOptions, System.Int32 scheduledCount)
UserManagementService.fetchCustomerRelatedDataAsync (XamApp.Models.Customer customer, Xamarin.Essentials.PermissionStatus status)
UserManagementService.RetrieveCustomerDataAsync (System.Int64 customerId, System.Boolean staySignedIn, System.Boolean goToDoseReminders, System.Boolean goToMedications, System.Nullable`1[T] cartOrderTarget, System.Nullable`1[T] conversationTarget, System.Nullable`1[T] announcementTarget, System.Nullable`1[T] deepLinkToRetrieveEScript, System.Boolean shouldNavigateAfterLogin)
HomePageViewModel.refreshPageAsync (Prism.Navigation.INavigationParameters navigationParameters)
BaseAsyncCommand`2[TExecute,TCanExecute].ExecuteAsync (TExecute parameter)
SafeFireAndForgetExtensions.HandleSafeFireAndForget[TException] (System.Threading.Tasks.Task task, System.Boolean continueOnCapturedContext, System.Action`1[T] onException)
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state)
SyncContext+<>c__DisplayClass2_0.<Post>b__0 ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
JNINativeWrapper.Wrap_JniMarshal_PP_V (_JniMarshal_PP_V callback, System.IntPtr jnienv, System.IntPtr klazz)
java.lang.SecurityException: Caller ###### needs to hold android.permission.SCHEDULE_EXACT_ALARM or android.permission.USE_EXACT_ALARM to set exact alarms.
android.os.Parcel.createExceptionOrNull Parcel.java:3057
android.os.Parcel.createException Parcel.java:3041
android.os.Parcel.readException Parcel.java:3024
android.os.Parcel.readException Parcel.java:2966
android.app.IAlarmManager$Stub$Proxy.set IAlarmManager.java:311
android.app.AlarmManager.setImpl AlarmManager.java:1084
android.app.AlarmManager.setImpl AlarmManager.java:1044
android.app.AlarmManager.setExactAndAllowWhileIdle AlarmManager.java:1312
Caused by: android.os.RemoteException: Remote stack trace:
com.android.server.alarm.AlarmManagerService$5.set AlarmManagerService.java:2981
android.app.IAlarmManager$Stub.onTransact IAlarmManager.java:181
android.os.Binder.execTransactInternal Binder.java:1339
android.os.Binder.execTransact Binder.java:1275

Anybody else having this issue?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 37 (18 by maintainers)

Most upvoted comments

Here is what I found out after testing for scheduling exact alarms if anyone is interested. (Xamarin)

Android

v12, you do not need any manifest permissions as alarm manager is enabled by default.

v13, you need to include in the manifest (android:name=“android.permission.SCHEDULE_EXACT_ALARM” android:maxSdkVersion=“33”)

v14 and above, you do not include anything in the manifest. The user needs to enable Alarms manually. So, you need to ask permission and redirect them to the Alarm Page.

Intent intent = new Intent(); intent.SetAction(Android.Provider.Settings.ActionRequestScheduleExactAlarm); intent.SetData(Android.Net.Uri.Parse(“package:” + context.PackageName)); intent.AddFlags(ActivityFlags.NewTask);

@LeoJHarris hmm ok. I will release a Xamarin version tonight.

If you have removed EXACT_ALARM permission because you dont need it and updated to V10.2.0-preview-01 then you should not have any more issues.

@thudugala I am going to close this issue as our Xamarin App is working fine on 10.2.0-preview01 thank you very much for offering this final support for Xamarin Apps.

@thudugala thanks for letting us know! 👍 Sounds like we will need to accelerate faster to a MAUI migration.

@cagriy, The current master code is for .Net 8. My App is in Xamarin Forms. I did build and try https://github.com/thudugala/Plugin.LocalNotification/tree/v10.1.8/Source But the same thing observed for OS >=13. OS does not allow SCHEDULE_EXACT_ALARM and Google does not allow USE_EXACT_ALARM for non Calendar Apps. Thanks for support.

@owenashurst The authors response or lack of is some what concerning, we have QA being put on hold until this can be resolved 😢

Having the same issue here #465.

The last release is quite old now, if master contains a fix for this, it’d be nice to have a new release soon. Google Play Developer Console is picking up on this issue for me which i’m concerned will halt my release to production.