How to Handle Version Differences in Android 12 Development? Key Tips Revealed!
This article will share my development experience with you,
focusing on the challenges and solutions brought by Android version upgrades.
By analyzing the problems I encountered,
I hope to provide some valuable insights for you when facing similar issues during the development process.
If you want to see what the official changes are,
you can directly go to
Android Developer
- Users can enable/disable through the quick buttons in the start bar or the
Camera or Microphone Access
switch in settings. -
This may affect the user experience with the camera,
even if the camera permission is enabled,
as long as the user disables camera access,
it will show a black screen for the camera.
The same applies to the microphone: Reference - Currently, the following code can be used to detect if the system supports it and provide a prompt to the user. There is no API to determine if it is enabled.
- However, in Android 13, it was tested that when
Accessibility Permission
is enabled, ACTION_CLOSE_SYSTEM_DIALOGS can still be sent. If not enabled, the broadcast will not be received.
- A new default icon splash screen is added as shown below:
-
After testing, there is currently no method to remove this default splash screen.
Only the method to remove the original custom Activity that does not display the screen but still runs the original cycle.
The official documentation also provides some specifications for the new splash screen: Reference - Adjustment approach:
- Add
implementation 'androidx.core:core-splashscreen:1.0.0'
to build.gradle
Note that the minimum SDK requirement is 21 and above.
-
Set the new splash screen Theme
windowSplashScreenBackground
is the background color, which can only be set to @color.
windowSplashScreenAnimatedIcon
is the icon for the circular view in the middle, which can be set to an image, but the size must follow the official specifications.
windowSplashScreenBrandingImage
is the small background image below the icon.
windowSplashScreenAnimationDuration
is the animation duration.
Other properties -
Add the new SplashTheme to
AndroidManifest.xml
- Add initial code
SplashScreen.installSplashScreen(this)
must be called beforesuper.onCreate
splashScreen.setKeepOnScreenCondition(() -> true );
This line ensures that the old activity screen does not display, but the activity lifecycle will still run.
However, this approach uses the new official splash screen, so the original customized screen will not be displayed. Product owners can consider this as needed. - Add
- As shown, when compiling and installing, the following error
INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
is displayed: - Additionally, when using PendingIntent, corresponding flags must be added to avoid errors:
- Solution & Demo:
- Add
FLAG_IMMUTABLE
orFLAG_MUTABLE
tags at each PendingIntent creation. - Also, add the latest work-runtime:
implementation 'androidx.work:work-runtime:2.7.1'
- Notes
- For example, in the Airdroid project, since Airdroid & httphelper repo are separate, other places also need to be corrected.
- Implicit PendingIntent also needs modification, as libraries used in the implementation may also use PendingIntent.
For instance, the current
Airdroid
project uses Google Analytics version 17.0.0, but errors are still prompted. (You will only know if there is a PendingIntent error when running that specific code segment) In this case, upgrading the version will suffice:implementation 'com.google.android.gms:play-services-analytics:18.0.1'
- Add
Since Chromium has removed this feature, the SDK no longer supports it: Reference
Currently, testing on SDK 32 shows that foreground services can still run in the background.
Initially tried running StartForegroundService in the background Service, and it worked fine. This will be monitored further.
The official recommendation is to use WorkManager as a replacement for execution: Reference
Alarm Manager API in Android 12 requires declaring the SCHEDULE_EXACT_ALARM
permission to use
When using registerListener() to register a sensor listener to monitor sensor events, the maximum sampling rate is limited to 200Hz
To use a higher Hz, you must add the HIGH_SAMPLING_RATE_SENSORS
permission
In this version, when requesting approximate/precise location permissions,
you need to request both ACCESS_FINE_LOCATION
and ACCESS_COARSE_LOCATION
simultaneously,
to display the new location permission request dialog
If you encounter this, take note: Reference
Previously, when using Bluetooth-related APIs, you needed to declare
Manifest.permission.BLUETOOTH_ADMIN
and Manifest.permission.ACCESS_FINE_LOCATION
to search for nearby Bluetooth devices
If you encounter using startDiscovery.. and other APIs to search for nearby devices
Using the old permissions when targeting API 32, API returns fail or some APIs directly crash
You can modify it like this:
- Add
android:maxSdkVersion="30"
to the old permissions - Declare new permissions
BLUETOOTH_CONNECT
,BLUETOOTH_SCAN
, orBLUETOOTH_ADVERTISE
as needed - Previously, runtime permission requests only required the
ACCESS_FINE_LOCATION
permission, now they are separated, and you need to add the aboveBluetooth permission requests
at runtime
Reference
API documentation
and Bluetooth permission separation explanation
Here is a simple demo on how to modify