Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

Splash screens 2

Slide 3

Slide 3 text

3 windowSplashScreenBackground windowSplashScreenAnimatedIcon windowSplashScreenIconBackgroundColor @color/... @drawable/... @color/...

Slide 4

Slide 4 text

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 } } } ) }

Slide 5

Slide 5 text

5 override fun onCreate(savedInstanceState: Bundle?) { // ... splashScreen.setOnExitAnimationListener { splashScreenView -> val animation = ObjectAnimator.ofFloat( /* ... */) animation.duration = 200L animation.doOnEnd { splashScreenView.remove() } animation.start() } }

Slide 6

Slide 6 text

RenderEffect 6

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Widgets 8

Slide 9

Slide 9 text

9 ● @android:dimen/system_app_widget_background_radius ● @android:dimen/system_app_widget_inner_radius Rounded corners

Slide 10

Slide 10 text

10 ● CheckBox ● Switch ● RadioButton New compound buttons

Slide 11

Slide 11 text

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) )

Slide 12

Slide 12 text

12 Responsive layouts

Slide 13

Slide 13 text

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)

Slide 14

Slide 14 text

14 Preview layout, description

Slide 15

Slide 15 text

Toast 15

Slide 16

Slide 16 text

Notification 16

Slide 17

Slide 17 text

17 Custom notifications

Slide 18

Slide 18 text

18

Slide 19

Slide 19 text

19 ● 通知から起動したService, Broadcast receiverからActivityを起動できない ● Indirect notification activity start (trampoline) from PACKAGE_NAME blocked Notification trampoline restrictions

Slide 20

Slide 20 text

Background Tasks 20

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

22 ● 数分以内に完了する短い重要なタスクをすぐに実行 ● DozeモードやBattery Saverの影響を受けにくい ● WorkManger Expedited jobs

Slide 23

Slide 23 text

23 val request = OneTimeWorkRequestBuilder() .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 } }

Slide 24

Slide 24 text

Approximate location 24

Slide 25

Slide 25 text

25

Slide 26

Slide 26 text

Bluetooth permissions 26

Slide 27

Slide 27 text

● getPrimaryClip でToast表示される ● getPrimaryClipDescription を使って現在のClipboardの情報を取得 Clipboard 27

Slide 28

Slide 28 text

Camera, Mic 28

Slide 29

Slide 29 text

29

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

31

Slide 32

Slide 32 text

Privacy dashboard 32

Slide 33

Slide 33 text

33

Slide 34

Slide 34 text

Safer component exporting 34

Slide 35

Slide 35 text

35 Manifest merger failed : android:exported needs to be explicitly specified for . 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

Slide 36

Slide 36 text

Kenji Abe - Android, Kotlin GDE / DeNA @STAR_ZERO Thank you! https://developer.android.com/about/ve rsions/12 Resources 36