Bernhard Piskernik
Bernhard Piskernik

Reputation: 145

Scheduling alarm not working on Android 12

When running on Android 12 and targeting SDK 31 scheduled alarms stopped working for me.

I schedule the alarm by

AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
            

PendingIntent alarmIntent = PendingIntent.getBroadcast(context, Constants_misc.CONST_INTENT_ALARM, intent, PendingIntent.FLAG_IMMUTABLE|FLAG_UPDATE_CURRENT);
alarmMgr.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000*60*15, alarmIntent);

The receiver looks like this:

public class AlarmReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent i) {
        Log.d(TAG, "alarm received");
        showNotification();
    }

//[...]
}

In the manifest, I have added the exact alarm permission

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

and added the receiver

<receiver
    android:name=".survey.AlarmReceiver"
    android:enabled="true"
    android:exported="false"
    android:process=":remote" />

On SDK <= 30 everything works as expected, but on Android 12 onReceive() is never called.

What do I miss?

Upvotes: 8

Views: 5126

Answers (1)

solved it for android 12 by adding this line to Manifest

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

Upvotes: 6

Related Questions