'PendingIntent fails when target API was upgraded from Android 10 to Android 12

I have an old android app that worked well with API 29 as a target.

Now I updated the target to API 31 (Android 12) and the test on an Android 12 phone fails as soon as I try to get the "PendingIntent":

Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(),myRequestCode,intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

I double checked some resources on the web but I cannot find a hint why this fails.

What can I do to narrow down the possible causes?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source