Android permission SCHEDULE_EXACT_ALARM required with USE_EXACT_ALARM for alarm app?
Asked Answered
W

1

10

My app, already published on Google Play and currently targetting Android 12, is an alarm clock app. In the latest release, I have used the SCHEDULE_EXACT_ALARM permission and also handled checking and requesting this permission at runtime, as required.

Upon checking the behaviour change for Android 13, I found that there is a new permission USE_EXACT_ALARM which has very restrictive use cases as listed here. My app is an alarm clock app, and hence it qualifies to use this permission. (An advantage of using this permission is that the system automatically grants it, and it cannot be revoked by the user.)

I added this permission to the AndroidManifest.xml file and removed the SCHEDULE_EXACT_ALARM permission. However, Android Studio gives me a lint warning on the method alarmManager.setAlarmClock(...):

enter image description here

This is what the warning reads:

Setting Exact alarms with setAlarmClock requires the SCHEDULE_EXACT_ALARM permission or power exemption from user; it is intended for applications where the user knowingly schedules actions to happen at a precise time such as alarms, clocks, calendars, etc. Check out the javadoc on this permission to make sure your use case is valid.

The Android Developers website says that I have the option to declare either of the permissions based on my use case. However, Android lint tells me that I should declare SCHEDULE_EXACT_ALARM irrespective of whether I have already declared USE_EXACT_ALARM.

What should I do? Follow the website and suppress lint?

Windsor answered 6/10, 2022 at 10:5 Comment(4)
I have exactly same problem, did you find an answer?Gamb
@Gamb I decided to use only USE_EXACT_ALARM by following the website. It seems that this supersedes the SCHEDULE_EXACT_ALARM permission.Windsor
Did you test on Android 12? On Android 12 if there is no SCHEDULE_EXACT_ALARM it will crash while settings alarmsGamb
for android 12 and 13 please refer to my solution her.Gowon
S
23

The answer's actually buried in the USE_EXACT_ALARM permission's documentation:

Apps need to target API Build.VERSION_CODES.TIRAMISU or above to be able to request this permission. Note that only one of USE_EXACT_ALARM or SCHEDULE_EXACT_ALARM should be requested on a device. If your app is already using SCHEDULE_EXACT_ALARM on older SDKs but need USE_EXACT_ALARM on SDK 33 and above, then SCHEDULE_EXACT_ALARM should be declared with a max-sdk attribute, like:

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

So it's kind of a conditional thing - if you're on 33+, then USE_EXACT_ALARM will be available, and the other one won't be requested at all.

Slaphappy answered 11/11, 2022 at 2:5 Comment(4)
Ah, OK. So we need both, and specify the max SDK for the older one. Thanks!Windsor
solution is not working for android 13!Gowon
this is quite messy and unnecessarily confusing, Googlers should really wake up and stop making life of devs so complicated. Permission handling on Android is one big mess, with these CONSTANT (and poorly thought-through) changes, I feel more like a lawyer than a developer. One needs to spend a week just studying changes in their policies 2-3x a year...Harlot
@Harlot In android 14 they again created complications. Don't don't why they can't make things simple to use.Rondeau

© 2022 - 2024 — McMap. All rights reserved.