Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Explore new updates on Android

Explore new updates on Android

In this slide, you will find out some key points
1) Android 13 Behaviour, Feature & APIs
2) Features and Improvements from Compose 1.2
3) Apps Adapility for all screen sizes.

Su Myat

July 23, 2022
Tweet

More Decks by Su Myat

Other Decks in Programming

Transcript

  1. Explore new updates on Android Android 13, Compose, Large Screens

    Google Developer Expert (Android) Senior Engineer @ Lomotif Su Myat Tun Extended Singapore
  2. Opt-in notification permission Applies to all newly installed apps, irrespective

    of targetSDK. For apps with targetSDK < 33, Android will typically ask for the Notification Permission on first launch. Notification Permission Privacy
  3. • Request when user is in-context • Provide rationale before

    requesting permission • No additional limits on prompting • Check notification access through PermissionChecker, or NotificationManager.areNotificationsEnabled UX - Following Best Practices
  4. Foreground Services Task Manager • Removes app from memory •

    Stops media playback • Stops the service, removing associated notification
  5. • Similar to Bluetooth in Android 12 ◦ Same permission

    group (NEARBY_DEVICES) • NEARBY_WIFI_DEVICES instead of ACCESS_FINE_LOCATION Updates - Wi-Fi Location Minimization
  6. Instead of READ_EXTERNAL_STORAGE: • READ_MEDIA_IMAGE for images • READ_MEDIA_VIDEO for

    video • READ_MEDIA_AUDIO for audio Updates - Media Permission
  7. If app requests both or only one permission at the

    same time: • READ_MEDIA_IMAGE for images • READ_MEDIA_VIDEO for video Updates - Media Permission
  8. Changes - Media Permission <manifest ...> <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <uses-permission

    android:name="android.permission.READ_MEDIA_AUDIO" /> <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" /> </manifest>
  9. Body Sensor - Need Background Permission <manifest ...> <uses-permission android:name="android.permission.BODY_SENSORS"/>

    <uses-permission android:name="android.permission.BODY_SENSORS_BACKGROUND"/> <application ...> ... </application> </manifest>
  10. Intents - Non-matching Now Blocked Intents are only delivered from

    external apps to apps targeting Android 13 or higher when they match an <intent-filter> element. There are a few exceptions: • Components without Intent filters • Intents from the system • Intents from root
  11. Preview - matching Intent //intent filter must specify <data> element

    to accept intents with data val intent = Intent(“previewtwo”) intent.data = Uri.parse("https://android.com") startActivity(intent) <receiver android:name=".MyReceiver" android:exported="true"> <intent-filter> <action android:name="previewtwo" /> + <data android:scheme="https" /> </intent-filter> </receiver>
  12. Safer Runtime Broadcast Receivers // set new flag while registering

    a runtime receiver if not SecurityException will be thrown // I want to receive broadcasts from other apps! context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_EXPORTED); // I don’t want to receive broadcasts from other apps! context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_NOT_EXPORTED);
  13. Battery Life is Important Restricted: Favor device battery life over

    app versatility, places more limitations on what app can do in background
  14. New Background Rules • When the system places your app

    in the restricted • What work your app can do when the user places your app in the restricted state. • Check if you’re in one of the restricted states: ◦ ActivityManager.isBackgroundRestricted () ◦ UsageStatsManager.getAppStandbyBuck et()
  15. Behavior Changes Summary Without targeting Android 13 • FGS Task

    Manager • Improved prefetch job handling • Battery resource utilization • Runtime notifications permission • Media controls derived from PlaybackState • In-app language pickers When targeting Android 13 • Nearby Wi-Fi runtime permission • Granular media permissions • Background body sensors permission • Intent filters block non-matching intents • Battery resource utilization
  16. • Ahead-of-time model allow the system to show preview of

    the destination • Deprecated KEYCODE_BACK or onBackPressed APIs Predictable Back Gesture
  17. <application ... //system will take control and play peaking anim

    android:enableOnBackInvokedCallback="true"> Optional opt-in flag in the manifest: Android 13 The new back dispatching will be enabled by default for application targeting SDK 34 Android 14 Once the new behavior is enabled, KEYCODE_BACK and onBackPressed() won't be used anymore. Application will have to rely entirely on the OnBackInvokedCallback Jetpack supports the new Back API androidx.activity:activity:1.6.0 Opt in the new behavior
  18. Themed App Icons • Inherit the coloring of user’s choonse

    wallpaper • Requires support for adaptive and monochromatic app icons <adaptive-icon > <background android:drawable="..." /> <foreground android:drawable="..." /> <monochrome android:drawable="@drawable/myicon" /> </adaptive-icon>
  19. • Should be VectorDrawable • logo fits within 44 x

    44 inside 108 x 188, can up to 72 x 72 • Flag logo Monochromatic icon specifications
  20. • System settings let user can selects preferred language for

    your app, not coupling with System language • API that let apps set different language at runtime Per-app Local Preferences
  21. In-app language pickers AndroidManifest.xml <application … android:localeConfig="@xml/locales_config"/> res\xml\locales_config.xml <?xml version="1.0"

    encoding="utf-8"?> <locale-config> <locale android:name="en-us" /> <locale android:name="ja" /> <locale android:name="fr" /> </locale-config>
  22. In-app Local Perference val appLocale: LocaleListCompat = LocaleListCompat.forLanguageTags("fr") // Call

    this on the main thread as it may require Activity.restart() AppCompatDelegate.setApplicationLocales(appLocale) //get in-app local language Val appLocale = AppCompatDelegate.getApplicationLocales() Update in-app local language
  23. • Recommended way to access user’s photos and videos •

    No runtime permissions • Better UX to access photos & videos • Continuously improved through Google Play System Updates • Backported to Android 11 & 12 • Will soon include cloud photos and albums Photo Picker
  24. Using the Photo Picker // Launches photo picker in single-select

    mode. // This means that the user can select one photo or video. val intent = Intent(MediaStore.ACTION_PICK_IMAGES) startActivityForResult(intent, PHOTO_PICKER_REQUEST_CODE)
  25. Using the Photo Picker // Launches photo picker in multi-select

    mode. // This means that the user can select multiple photos/videos, up to the limit. // specified by the app in the extra (10 in this example). val maxNum = 10 val intent = Intent(MediaStore.ACTION_PICK_IMAGES) intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX,maxNum) startActivityForResult(intent, PHOTO_PICKER_MULTI_SELECT_RC)
  26. Handle the Photo Picker results // onActivityResult() handles callbacks from

    the photo picker. override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { when(resultCode) { PHOTO_PICKER_REQUEST_CODE -> { // Get photo picker response for single select. val currentUri: Uri = data.data return } PHOTO_PICKER_MULTI_SELECT_RC -> { // Get photo picker response for multi select. var results = data.clipData return }
  27. Downgradeable Permissions // Downgrade single permission @RequiresApi(33) fun revokeSelfPermissionOnKill(permName: String):

    Unit // Downgrade permission group @RequiresApi(33) fun revokeSelfPermissionOnKill(permissions:MutableCollection<String!>): Unit
  28. • Copy and Past UI to Clipboard • Provides a

    preview of the copied content • Sensitive content to clipboard • Programmable Shaders Other changes
  29. Compose 1.2 Downloadable Fonts @OptIn(ExperimentalTextApi::class) val provider = GoogleFont.Provider( providerAuthority

    = "com.google.android.gms.fonts", providerPackage = "com.google.android.gms", certificates = R.array.com_google_android_gms_fonts_certs) val fontName = GoogleFont("Lobster Two") val fontFamily = FontFamily(Font(googleFont = GoogleFont(fontName), fontProvider = provider))
  30. Compose 1.2 Text( text = myText, style = TextStyle( lineHeight

    = 2.5.em, platformStyle = PlatformTextStyle( includeFontPadding = false ), lineHeightStyle = LineHeightStyle( alignment = Alignment.Center, trim = Trim.None ) ) ) Set includeFontPadding true to left vs right fase and LineHeightSytle
  31. Lazy Layouts Develop gradually with the grid APIs LazyVerticalGrid and

    LazyHorizontalGrid Compose 1.2 @Composable fun FavoriteCollectionsGrid( modifier: Modifier = Modifier ) { LazyHorizontalGrid( rows = GridCells.Fixed(2), modifier = modifier ) { items(favoriteCollectionsData) { item -> FavoriteCollectionCard(item.drawable, item.text) } } }
  32. Nested Scrolling Interop Scrolling composable in Coordinator layout is much

    smoother Things like Collapsing Toolbar are easy to set up Compose 1.2
  33. Android 12L & 13 Improved taskbar for app switching Allow

    Drag and Drop Resizable Window Don’t assume your app will be only used in a certain orientation Don’t assume your app will be only used through a touch screen Multi-window by default Compatibility mode Input support
  34. a lot of broken assumptions means a lot of code

    to be changed in your app? Development Changes
  35. Jetpack WindowManager: stable release, provide common API surface for supporting

    different device types, starting with foldables and tablet Window Metrics: access currentWindowMetric, maxWindowMetric in advance Window size classes: provide opinionated layout breakpoints for you to know how to adapt your UI based on screen size, partition as compact, medium, expended Activity embedding: allows displaying two Activities simultaneously, with each taking up a portion of the window. SlidingPaneLayout: Places content side by side if the window size allows Resizable and desktop emulators Large Screens made easy