简体   繁体   中英

App is not shown in Alarms & Reminders besides setting the SCHEDULE_EXACT_ALARM permission in manifest

As the title says, I have an app that targets Android 12 with compileSdkVersion = 31 and should trigger an exact alarm. The issue here is that the app is given the SCHEDULE_EXACT_ALARM permission in the manifest but it isn't shown in Alarms & Reminders list.

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

<application
  ...
    <receiver
        android:name=".boot.AlarmReceiver"
        android:exported="false"
        <intent-filter>
            <action android:name="android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED" />
        </intent-filter>
    </receiver>
 ...
</application>

I've tried debugging it using ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED in the broadcast receiver which also includes intent filter and the intent action to check whether if listens to that change and forcefully changing the REQUIRE_EXACT_ALARM_PERMISSION permission through App Compatibility Changes in Developer settings which it works.

    private fun runOnBootCompleted(intentAction: String) {
    if (intentAction == AlarmManager.ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED
    ) {                
     alarmManager.setRepeatingAlarm()
    }
}

Before setting the alarm I am checking whether the permission for it has been granted

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&!alarmManager.canScheduleExactAlarms()) {
                    openAlarmSettings()
                } else {
                    setRepeatingAlarm()
                }
            

This works perfectly, even when turning off the REQUIRE_EXACT_ALARM_PERMISSION it behaves as it should.

Is there something that I am missing which should be required for the app to be shown in the Alarms & Reminders list?

You need to set -

    androidCompileSdkVersion = 31
    androidTargetSdkVersion = 31

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM