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

Compose におけるパスワード自動入力とパスワード保存

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Compose におけるパスワード自動入力とパスワード保存

Avatar for tonionagauzzi

tonionagauzzi

April 29, 2025
Tweet

More Decks by tonionagauzzi

Other Decks in Technology

Transcript

  1. Compose での実装方法 Compose UI 1.8.0以降がおすすめ 2025/4/23 に正式リリース // build.gradle.kts(:app) dependencies

    { implementation("androidx.compose.ui:ui:1.8.0") } 1.7.x以下では AutofillType (deprecated)を使う必要あり 実験的APIで正常に機能しないことも Compose におけるパスワード自動入力とパスワード保存 Sansan×DMM.com Android Tech Talk 10
  2. Composeでの自動入力実装 // SomeComposable.kt Column { TextField( value = username.value, onValueChange

    = {username.value = it}, modifier = Modifier.semantics { contentType = ContentType.Username } ) TextField( value = password.value, onValueChange = {password.value = it}, modifier = Modifier.semantics { contentType = ContentType.Password } ) } 公式ドキュメントを参考に、 Modifier.semantics { contentType = } で実装 Compose におけるパスワード自動入力とパスワード保存 Sansan×DMM.com Android Tech Talk 11
  3. 新しいパスワードの自動生成 パスワード再設定画面などのユースケース ContentType.NewPassword を使用 強力なパスワードを自動生成して提案 TextField( value = newPassword.value, onValueChange

    = {newPassword.value = it}, modifier = Modifier.semantics { contentType = ContentType.NewPassword } ) Compose におけるパスワード自動入力とパスワード保存 Sansan×DMM.com Android Tech Talk 13
  4. パスワード保存機能の実装 公式ドキュメントでは autofillManager?.commit() を使う方法が紹介されている val autofillManager = LocalAutofillManager.current 〜省略〜 Button(onClick

    = { autofillManager?.commit() }) { Text("Reset credentials") } Compose におけるパスワード自動入力とパスワード保存 Sansan×DMM.com Android Tech Talk 14
  5. 解決策:CredentialManagerを使う Button(onClick = { coroutineScope.launch { val credentialManager = CredentialManager.create(context)

    val request = CreatePasswordRequest(username, newPassword.value) credentialManager.createCredential( request = request, context = context, ) } }) { Text("Reset credentials") } Compose におけるパスワード自動入力とパスワード保存 Sansan×DMM.com Android Tech Talk 18
  6. CredentialManagerの注意点 android.credentials (API Level 34以上) androidx.credentials (下位互換性あり) API Level 33以下をサポートする場合は

    androidx.credentials を使用 // build.gradle.kts(:app) dependencies { implementation("androidx.credentials:credentials:1.5.0") // optional - needed for credentials support from play services, for devices running // Android 13 and below. implementation("androidx.credentials:credentials-play-services-auth:1.5.0") } Compose におけるパスワード自動入力とパスワード保存 Sansan×DMM.com Android Tech Talk 19
  7. まとめ Compose UIでの自動入力は contentType で簡単に実装可能 パスワード保存は AutofillManager より CredentialManager が確実

    適切な実装でユーザー体験を向上させよう Compose におけるパスワード自動入力とパスワード保存 Sansan×DMM.com Android Tech Talk 20