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] Your app schedules exact alarms without checking whether the SCHEDULE_EXACT_ALARM permission has been granted. #465

Open
owenashurst opened this issue Jan 13, 2024 · 17 comments
Assignees
Labels
Android Android only issue bug Something isn't working

Comments

@owenashurst
Copy link

owenashurst commented Jan 13, 2024

Describe the bug
When publishing release builds to the Google Play Developer Console, I found that it is showing me an error for the SCHEDULE_EXACT_ALARM permission. The exact error is:

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.

In most cases, alternative methods of scheduling work or inexact alarms are more appropriate. If your use of exact alarms is justified, update your app so that it checks this permission is granted before scheduling.

The AndroidManifest has the permissions enabled outlined in the Wiki for this plugin, including the SCHEDULE_EXACT_ALARM permission. When testing via debug, I can see the notification that was scheduled fine (Google Pixel 5 emulator & My own Google Pixel 7 Pro).

I'm aware you can use Android specific namespaces to request this permission manually, however the issue is I am planning to also make a build for iOS, and from my experience prior to knowing about this plugin, I tried to create notifications via Intent, however the build would fail since iOS does not know about Android specific code. Even by conditionally registering an Android class via Dependency Injection with #if Android.

To Reproduce
Steps to reproduce the behavior:

  1. Install Plugin.LocalNotifications
  2. Set a notification to appear by scheduling a DateTime.
  3. Publish the release to Google Play Console (Internal testing etc)
  4. See error

Expected behavior
I should expect the plugin to have the ability to request missing permissions that it uses internally, instead of just one ability to Request Notification permissions.

Platform (please complete the following information):

  • OS: Android
  • Version 14

Smartphone (please complete the following information):

  • Device: Google Pixel
  • OS: Android
  • Version 14
@vallgrenerik
Copy link

Im also facing this!
Did you @owenashurst find any solution?
Ping @thudugala

@owenashurst
Copy link
Author

owenashurst commented Jan 26, 2024

Im also facing this!
Did you @owenashurst find any solution?
Ping @thudugala

Nope! I read a comment on another issue that a potential fix is in master. There needs to be a new release ideally. I tried cloning the code and including it in the project but I had all sorts of issues. Plus that didn't seem right to me.

@thudugala
Copy link
Owner

thudugala commented Feb 20, 2024

@owenashurst new releases are planned only to be release using .Net 8 Maui

also does not require

<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />

@owenashurst
Copy link
Author

@owenashurst new releases are planned only to be release using .Net 8 Maui

also does not require

<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />

Thanks for the reply @thudugala.

I'm already targeting .NET 8 since it's a relatively new app. Could you provide an estimate on when you plan to release the new version, please?

@thudugala
Copy link
Owner

@owenashurst can release new version, if you do not any issues with latest pre release version

@owenashurst
Copy link
Author

owenashurst commented Feb 20, 2024

@owenashurst can release new version, if you do not any issues with latest pre release version

@thudugala Just installed the pre-release, and it seems to still work fine (for android at least). I think you're good. I'm ready to deploy a new version of my app, so I'm happy to update once you release so I can publish.

Quick question, are you saying I can remove the following permissions after your release?

<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />

@thudugala
Copy link
Owner

@owenashurst yes.

But please remember notification will not pop up at the exact time.

Try with the pre release

@owenashurst
Copy link
Author

@owenashurst yes.

But please remember notification will not pop up at the exact time.

Try with the pre release

@thudugala My app doesn't need to be exact. As long as it shows the notification +- a few seconds and not minutes.

I've just tried with the above permissions removed and it was still relatively exact. Although this was inside an Android Emulator.

Does that mean it's good?

@thudugala
Copy link
Owner

@owenashurst yes.

@owenashurst
Copy link
Author

@thudugala Brilliant. Looking forward to the release. Thank you.

@thudugala
Copy link
Owner

Will release tonight at about 10 pm New Zealand time

@thudugala
Copy link
Owner

@owenashurst Please try version 11.1.0

@vallgrenerik
Copy link

Thanks for the update @thudugala

In the Wiki you have:

[assembly: UsesPermission(Manifest.Permission.WakeLock)]

//Required so that the plugin can reschedule notifications upon a reboot
[assembly: UsesPermission(Manifest.Permission.ReceiveBootCompleted)]
[assembly: UsesPermission(Manifest.Permission.Vibrate)]
[assembly: UsesPermission("android.permission.POST_NOTIFICATIONS")]

optional
[assembly: UsesPermission("android.permission.USE_EXACT_ALARM")]
[assembly: UsesPermission("android.permission.SCHEDULE_EXACT_ALARM")]

Could you elaborate, when should we use the optional permissions and when should we avoid them? :)

@thudugala
Copy link
Owner

@vallgrenerik if you want notifications to fire at the exact time you need the optional permission.

@thudugala thudugala added the Android Android only issue label Feb 21, 2024
@andrea-torre
Copy link

Hi, I'm having this problem too, in Google Play Console I can see the same warning for Android 14 that the original poster described. My App is developed with .net 7.0. It's not clear to me if I have to update to version 11.1.0 and .net 8.0 in order to solve the problem or if it is possible to deal with the permissions also without porting to .net 8.0. Thank you

@alexsmi-noveo
Copy link

For .NET8.0 Google Play fires me warning: "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".

I was managed to request SCHEDULE_EXACT_ALARM permission (Android, API 31+) using android native classes (MainActivity.cs):

AlarmManager alarmManager = AlarmManager.FromContext(Platform.AppContext);
var isPermissionSet = alarmManager.CanScheduleExactAlarms();

if (!isPermissionSet)
{
    Android.Net.Uri uri = Android.Net.Uri.Parse("package:" + Android.App.Application.Context.ApplicationInfo.PackageName);
    //https://developer.android.com/reference/android/provider/Settings#ACTION_REQUEST_SCHEDULE_EXACT_ALARM  
    Intent intent = new Intent(Android.Provider.Settings.ActionRequestScheduleExactAlarm, uri);
    StartActivity(intent);
}

@Kebechet
Copy link
Contributor

Kebechet commented May 13, 2024

Except the permissions in AndroidManifest consider adding AndroidNotificationPermission

private static NotificationPermission _notificationPermissions = new()
{
	Android = new AndroidNotificationPermission()
	{
		RequestPermissionToScheduleExactAlarm = true,
	}
};

and then call:

var areNotificationsEnabled = await notificationService.AreNotificationsEnabled(_notificationPermissions);

await notificationService.RequestNotificationPermission(_notificationPermissions);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Android only issue bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants