I updated to targetSdkVersion 31 today and noticed that my pending intents for sleep, location, and activity transition stopped working.
So instead of just using UPDATE_CURRENT, I changed to;
int flags = PendingIntent.FLAG_UPDATE_CURRENT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
flags |= PendingIntent.FLAG_MUTABLE;
}
Intent intent = new Intent(context, SleepUpdatesBroadcastReceiver.class);
intent.setAction(SleepUpdatesBroadcastReceiver.MY_SLEEP_UPDATES_BROADCAST);
pendingIntent = PendingIntent.getBroadcast(context, 0, intent, flags);
Task requestTask = ActivityRecognition.getClient(context).requestSleepSegmentUpdates(pendingIntent, SleepSegmentRequest.getDefaultSleepSegmentRequest());
Then it works again but Android Studio keeps showing a WrongConstant warning for the flags parameter saying:
Must be one or more of: PendingIntent.FLAG_ONE_SHOT, PendingIntent.FLAG_NO_CREATE, PendingIntent.FLAG_CANCEL_CURRENT, PendingIntent.FLAG_UPDATE_CURRENT, PendingIntent.FLAG_IMMUTABLE, android.app.PendingIntent.FLAG_MUTABLE, Intent.FILL_IN_ACTION, Intent.FILL_IN_DATA, Intent.FILL_IN_CATEGORIES, Intent.FILL_IN_COMPONENT, Intent.FILL_IN_PACKAGE, Intent.FILL_IN_SOURCE_BOUNDS, Intent.FILL_IN_SELECTOR, Intent.FILL_IN_CLIP_DATA
So, again, it does seem to work fine now on my Pixel 3a with Android 12 but I am a bit confused about the warning.