Put the setAlarmClock of the Android11 (API30) target resource on standby in the Android Emulator of Android12 (API31). Close the app. Upgrade to Android12 (API31) target resource.
java.lang.RuntimeException: Unable to start receiver com.xxx.xxx.AlarmReceiver: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.xxx.xxx/.AlarmService
The above error occurs.
It operates normally when the above conditions are not met.
Below is the source.
am.setAlarmClock(new AlarmManager.AlarmClockInfo(alarmRun, showIntent1), pendingIntent2);
Receiver
context.startForegroundService(new Intent(context, AlarmService.class));
Is it a bug in the Android Emulator?
Will the situation be the same on the actual machine?
I can't test because I don't own the actual Android 12.