7

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?

Wrichik Basu
  • 1,005
  • 17
  • 28

2 Answers2

12

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.

cactustictacs
  • 17,935
  • 2
  • 14
  • 25
0

USE_EXACT_ALARM is a restricted permission that is granted automatically. Users can not revoke this permission.
Since this permission is a restricted permission, apps that request this restricted permission are subject to review, and those that do not meet the acceptable use case criteria will be disallowed from publishing on Google Play.

Your app must use the USE_EXACT_ALARM functionality only when your app’s core, user-facing functionality requires precisely-timed actions, such as:

  1. The app is an alarm or timer app.
  2. The app is a calendar app that shows event notifications.

This restriction is mentioned in the Google Android permission policies list here: https://support.google.com/googleplay/android-developer/answer/9888170?sjid=10510309997098831402-AP

So if your app is NOT an alarm or a calendar app, consider using SCHEDULE_EXACT_ALARM permission

More on how to use this permission is mentioned here in the tutorial

N-JOY
  • 10,344
  • 7
  • 51
  • 69