0

onReceive() is called by all other API levels but for some reason is not called by API 33.

As far as I understand as of API 31 SCHEDULE_EXACT_ALARM permission is needed and auto allowed however after API 33 no longer auto set as true.

However as of API 33 USE_ALARM is available which is allowed from install and SCHEDULE_EXACT_ALARM is no longer needed in this case.

my permissions:

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

alarm manager:

fun schedule(context: Context) {
    val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
    val intent = Intent(context, AlarmReceiver::class.java)
    intent.putExtra("once", once)
    intent.putExtra("vibrate", vibrate)
    intent.putExtra("shake", shake)
    intent.putExtra("snooze", snooze)
    val alarmPendingIntent = PendingIntent.getBroadcast(
        context,
        alarmId, intent,
        PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
    )
    val calendar: Calendar = Calendar.getInstance()
    calendar.timeInMillis = System.currentTimeMillis()
    calendar.set(Calendar.HOUR_OF_DAY, hour)
    calendar.set(Calendar.MINUTE, minute)

    //if alarm time has already passed, increment day by 1
    if (calendar.timeInMillis <= System.currentTimeMillis()) {
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 1)
    }

    val alarmInfo = AlarmClockInfo(calendar.timeInMillis, alarmPendingIntent)
}

As mentioned above this problem is specific to android 13. If there is something more specific I should post here please let me know in a comment and I can update.

Joe Pleavin
  • 436
  • 1
  • 4
  • 21

2 Answers2

1

android adding DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION in release build

Did you look at how how Android 13 changed some of the permissions / manifest settings for this to work?

Kevin
  • 1,405
  • 15
  • 16
0

According to Android Developers Documentation to AlarmManager there is a method canScheduleExactAlarms

Have you tried to call the method and check if you can schedule exact alarms?

Moreover, the documentation also says two things:

Apps targeting Build.VERSION_CODES#S or higher can schedule exact alarms only if they have the Manifest.permission#SCHEDULE_EXACT_ALARM permission or they are on the device's power-save exemption list.

So it means you should have SCHEDULE_EXACT_ALARM in your manifest, which you seem to declare.

These apps can also start Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM to request this permission from the user.

Note: Applications are still required to check canScheduleExactAlarms() before using the above APIs after receiving this broadcast, because it's possible that the permission is already revoked again by the time applications receive this broadcast.

You should also request a permission from the user to schedule exact alarms. Did you do this?