androidalarmmanagerschedulerandroid-alarmsandroid-workmanager

Android 12: Using SCHEDULE_EXACT_ALARM permission to get/show data at specific time are safe in Google Play Policy?


I have an Android app on Play store for 8 years. Recently Google release Android S or 12 introduce some limit with Foreground service launch restrictions

https://developer.android.com/about/versions/12/behavior-changes-12#foreground-service-launch-restrictions

and Exact alarm permission

https://developer.android.com/about/versions/12/behavior-changes-12#exact-alarm-permission

In the app I use foreground service and alarm clock to schedule update weather data from the cloud and device sensor and send notification to user, update the widget. But they said: Exact alarms should only be used for user-facing features so if I continue use those API, it is safe (with Google Play policy)?

I ask this because other solution like sticky notification with foreground service and workmanager not work as my requirements.


Solution

  • if you are testing android 12 then don't forget to add this line to Manifest

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

    Update:

    Android 13 generated a security exception and solution was to add below two lines in manifest:

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

    Update for Android 14 :

    crash for users on Android 14 because the permission is no longer granted by default. This means a runtime check should be done and if not granted then you should grant it programatically