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

What's new Android 12

What's new Android 12

80a3a3857a55f154d23acb705eff72cc?s=128

star_zero

June 20, 2021
Tweet

Transcript

  1. Kenji Abe - Android, Kotlin GDE / DeNA @STAR_ZERO What's

    new Android 12 Android 12 1
  2. Splash screens 2

  3. 3 windowSplashScreenBackground windowSplashScreenAnimatedIcon windowSplashScreenIconBackgroundColor <item name="android:windowSplashScreenBackground">@color/...</item> <item name="android:windowSplashScreenAnimatedIcon">@drawable/...</item> <item name="android:windowSplashScreenIconBackgroundColor">@color/...</item>

  4. 4 override fun onCreate(savedInstanceState: Bundle?) { // ... val content:

    View = findViewById(android.R.id.content) content.viewTreeObserver.addOnPreDrawListener( object : ViewTreeObserver.OnPreDrawListener { override fun onPreDraw(): Boolean { return if (viewModel.isReady) { // 準備完了 content.viewTreeObserver.removeOnPreDrawListener(this) true } else { // 準備中 false } } } ) }
  5. 5 override fun onCreate(savedInstanceState: Bundle?) { // ... splashScreen.setOnExitAnimationListener {

    splashScreenView -> val animation = ObjectAnimator.ofFloat( /* ... */) animation.duration = 200L animation.doOnEnd { splashScreenView.remove() } animation.start() } }
  6. RenderEffect 6

  7. 7 imageView.setRenderEffect( RenderEffect.createBlurEffect( 20F, 20F, Shader.TileMode.MIRROR ) )

  8. Widgets 8

  9. 9 • @android:dimen/system_app_widget_background_radius • @android:dimen/system_app_widget_inner_radius Rounded corners

  10. 10 • CheckBox • Switch • RadioButton New compound buttons

  11. 11 // CheckBox remoteView.setCompoundButtonChecked(R.id.check, true) // RadioGroup remoteView.setRadioGroupChecked(R.id.radio_group, R.id.radio_1) //

    Checkイベント remoteView.setOnCheckedChangeResponse( R.id.check, RemoteViews.RemoteResponse.fromPendingIntent(pendingIntent) )
  12. 12 Responsive layouts

  13. 13 val listView = RemoteViews(...) val gridView = RemoteViews(...) val

    viewMapping = mapOf( SizeF(150f, 110f) to listView, SizeF(250f, 110f) to gridView ) val removeViews = RemoteViews(viewMapping) appWidgetManager.updateAppWidget(appWidgetId, removeViews)
  14. 14 Preview layout, description <appwidget-provider ... android:previewLayout="@layout/..." android:description="@string/..." />

  15. Toast 15

  16. Notification 16

  17. 17 Custom notifications

  18. 18

  19. 19 • 通知から起動したService, Broadcast receiverからActivityを起動できない • Indirect notification activity start

    (trampoline) from PACKAGE_NAME blocked Notification trampoline restrictions
  20. Background Tasks 20

  21. 21 • 特別なケースを除いて、バックグラウンドからForeground Serviceを実行できなくなる ◦ ForegroundServiceStartNotAllowedException • 特別なケース ◦ Notification,

    Widgetのタップなど ◦ high-priorityのFCMメッセージ ◦ BOOT_COMPLETED、MY_PACKAGE_REPLACEDのブロードキャスト ◦ https://developer.android.com/about/versions/12/foreground-services#cases-fgs-background-starts-allowed Foreground service launch restrictions
  22. 22 • 数分以内に完了する短い重要なタスクをすぐに実行 • DozeモードやBattery Saverの影響を受けにくい • WorkManger Expedited jobs

  23. 23 val request = OneTimeWorkRequestBuilder<SampleWork>() .setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST) .build() WorkManager.getInstance(context).enqueue(request) // Worker

    class SampleWork(...) : CoroutineWorker(...) { override suspend fun doWork(): Result { // ... return Result.success() } override suspend fun getForegroundInfo(): ForegroundInfo { // Android 12未満のときはForeground Service } }
  24. Approximate location 24

  25. 25 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

  26. Bluetooth permissions 26 <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> <uses-permission

    android:name="android.permission.BLUETOOTH_CONNECT" />
  27. • getPrimaryClip でToast表示される • getPrimaryClipDescription を使って現在のClipboardの情報を取得 Clipboard 27

  28. Camera, Mic 28

  29. 29

  30. • アプリの休止状態 • ストレージの最適化とキャッシュの削除 • バックグラウンドジョブの停止 • FCMメッセージの受信停止 App hibernation

    30
  31. 31

  32. Privacy dashboard 32

  33. 33

  34. Safer component exporting 34 <activity android:name=".MainActivity" android:exported="true"> <intent-filter> <!-- ...

    --> </intent-filter> </activity>
  35. 35 Manifest merger failed : android:exported needs to be explicitly

    specified for <activity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. Build error message Lint warning When using intent filters, please specify android:exported as well
  36. Kenji Abe - Android, Kotlin GDE / DeNA @STAR_ZERO Thank

    you! https://developer.android.com/about/ve rsions/12 Resources 36