Thursday 18 August 2022

Migrating android apps to android 12 or later versions

Android 12 rethinks the entire user interface, from shapes, light and motion, to customisable system colours that can be adapted to match you. Redesigned to be more spacious and comfortable, it’s our most expressive, dynamic and personal OS ever.


1. Safe Export
 Its is necessary to explicitly export the component from api 31 onwards. whether android:exported="false" OR android:exported="true" 

For launcher it will be always android:exported="true" because its called by android OS.
<activity android:name=".LauncherActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>


Any application component which is using intent filters needs to be used android:exported="true"


2. Pending intents Mutability
Its necessary to use the PendingIntent as 
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_IMMUTABLE

val updatedPendingIntent = PendingIntent.getActivity(
   applicationContext,
   NOTIFICATION_REQUEST_CODE,
   updatedIntent,
   PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)

3. SplashScreen

Now need to use SplashScreen api instead of our custom splash.

Reference
https://developer.android.com/guide/topics/ui/splash-screen

4. Web Intent Resolution

Starting in Android 12 (API level 31), a generic web intent resolves to an activity in your app only if your app is approved for the specific domain contained in that web intent. If your app isn't approved for the domain, the web intent resolves to the user's default browser app instead.

https://developer.android.com/training/app-links/verify-site-associations

5. Exact alarm improvements
SCHEDULE_EXACT_ALARM permission needs to be added in the manifest to get this special app access.

https://developer.android.com/training/scheduling/alarms#exact

6. Custom notifications

https://qonversion.io/blog/custom-push-notifications-android-12/