Android 12 is in Beta and apps are almost ready for Android 12. The following is a list of the major Android S adaptations that are affected: Apps with targetSDKVersion for Android 12.
The exported property
If you declare an Intent-filter component exported, the default value is true. On Android S, you need to explicitly declare the exported property on the component containing the Intent-Filter.
If you do not declare the exported property, the following error will appear on a machine that installed APK on Android Studio to Android 12. When the following error occurs, you need to see if the exported components in the Manifest have all declared exported properties.
Installation did not succeed.
The application could not be installed: INSTALL_FAILED_VERIFICATION_FAILURE
Copy the code
In fact, this is not a lot of adaptation work, the difficult is the three SDK export components need to adapt.
PendingIntent must declare variability
To declare whether a particular PendingIntent is mutable, use the pendingIntent. FLAG_MUTABLE or pendingIntent. FLAG_IMMUTABLE flags, respectively. If your application tries to create a PendingIntent object without setting any mutable flags, the system throws an IllegalArgumentException
PACKAGE_NAME: Targeting S+ (version 10000 and above) requires that one of \
FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if \
some functionality depends on the PendingIntent being mutable, e.g. if \
it needs to be used with inline replies or bubbles.
Copy the code
Example of adaptation: before
PendingIntent pendingActivityIntent = PendingIntent.getActivity(Application.getContext(), R.drawable.ic_launcher, intent,
PendingIntent.FLAG_ONE_SHOT);
Copy the code
Android 12 and beyond
PendingIntent pendingActivityIntent = PendingIntent.getActivity(Application.getContext(), R.drawable.ic_launcher, intent,
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
Copy the code
Third, in the background to start the limitation of the foreground service
With few exceptions, applications cannot start foreground services while in the background.
exceptions
Unable to create notification trampoline via service or broadcast receiver
Apps targeting Android 12 cannot start an activity from a service or broadcast receiver used as a notification trampoline. In other words, your application cannot call startActivity() in a service or broadcast receiver when the user clicks on a notification or action button in a notification. The system prevents such a startup and prints the log
Indirect notification activity start (trampoline) from PACKAGE_NAME, \
this should be avoided for performance reasons.
Copy the code
Migration mode: Use PendingIntent
[1] Behavior change: Apps targeting Android 12