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(...)
:
This is what the warning reads:
Setting Exact alarms with
setAlarmClock
requires theSCHEDULE_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?
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 ofUSE_EXACT_ALARM
orSCHEDULE_EXACT_ALARM
should be requested on a device. If your app is already usingSCHEDULE_EXACT_ALARM
on older SDKs but needUSE_EXACT_ALARM
on SDK 33 and above, thenSCHEDULE_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.