【问题标题】:setAuthentication method doesn't work with autofillsetAuthentication 方法不适用于自动填充
【发布时间】:2021-10-31 23:36:35
【问题描述】:

我在我的应用中使用自动填充服务。但是这样做有两个问题:

  1. 单击用户名/密码字段时,演示视图闪烁。有时会出现,有时不会。
  2. 当我使用 setAuthentication 方法并从我的活动中返回数据集时,它不起作用。它适用于自动填充常规应用,但不适用于网络浏览器。

我已经看到很多关于 chrome 等问题的报告,但自动填充似乎可以正常工作,例如 Bitwarden 或 Lastpass 应用程序。

这是我在 onFillRequest 中的代码:

创建演示文稿:

val manualPresentation = createPresentation("Select password")

创建数据集:

val dataSet = Dataset.Builder()
            .setValue(
                passwordParsedAssistStructure.id,
                AutofillValue.forText(null)
            )
            .setValue(
                usernameParsedAssistStructure.id,
                AutofillValue.forText(null)
            )
 val intent = Intent(applicationContext, AutofillActivity::class.java)
        
val sender = PendingIntent.getActivity(
            applicationContext, id, intent,
            PendingIntent.FLAG_CANCEL_CURRENT
        ).intentSender

val ids = arrayOf(passwordParsedAssistStructure.id, usernameParsedAssistStructure.id)

     
return FillResponse.Builder()
    .addDataset(
                dataSet.build()
            )
    .setAuthentication(ids, sender, manualPresentation)
    .build()

另外,我将这些 id 传递到我的活动中,然后返回它:

 val returnDataset = Dataset.Builder()

        returnDataset.setValue(
            passwordId,
            AutofillValue.forText(String(password))
        ).setValue(
            userId,
            AutofillValue.forText(username)
        )

        val responseBuilder = FillResponse.Builder()
        responseBuilder.addDataset(returnDataset.build())

val replyIntent = Intent().apply {
            putExtra(EXTRA_AUTHENTICATION_RESULT, responseBuilder.build())
}

setResult(Activity.RESULT_OK, replyIntent)
finish()

我做错了什么? setAuthentication 方法应该设置在dataSet 还是fillResponse 上? Activity 应该返回 Dataset 还是 FillResponse?

【问题讨论】:

    标签: android android-autofill-manager


    【解决方案1】:
    1. 它需要在其清单中具有android.permission.BIND_AUTOFILL_SERVICE 权限。

    2. 用户使用 Android 设置显式启用它(Settings#ACTION_REQUEST_SET_AUTOFILL_SERVICE 意图可用于启动此类设置屏幕)。

    如果您对数据集标签和数据集数据进行加密,当需要用户交互来解锁他们的数据保险库时,这通常很有用。建议仅加密敏感数据而不是数据集标签,这将允许在数据集级别进行身份验证,从而带来更好的用户体验。请注意,如果您使用敏感数据作为标签,例如电子邮件地址,那么它也应该被加密。提供的intent 必须是实现您的身份验证流程的Activity。此外,如果您提供身份验证意图,您还需要指定要在填充 UI 中显示的演示视图,以便用户触发您的身份验证流程。

    当用户触发自动填充时,系统会启动提供的意图,其额外内容将具有screen content 和您的client state。完成身份验证流程后,您应该将Activity 结果设置为Activity.RESULT_OK,并将AutofillManager.EXTRA_AUTHENTICATION_RESULT 额外设置为完全填充的response(如果屏幕无法自动填充,则设置为null)。

    例如,如果您提供了一个空的response,因为用户的数据被锁定并标记了响应需要身份验证,那么在身份验证成功时返回的响应中,您需要提供所有可用的数据集,其中一些可能需要进一步验证,例如需要输入 CVV 的信用卡。

    如果您提供身份验证意图,则还必须提供一个演示文稿,用于可视化触发身份验证流程的响应。

    new FillResponse.Builder() .addDataset(new Dataset.Builder() .setValue(id1, AutofillValue.forText("homer"), createPresentation("homer")) .setValue(id2, AutofillValue.forText("D'OH!"), createPresentation("password for homer")) .build()) .build();

    参考请查看

    https://developer.android.com/reference/android/service/autofill/FillResponse.Builder#setAuthentication(android.view.autofill.AutofillId[],%20android.content.IntentSender,%20android.widget.RemoteViews)

    https://developer.android.com/reference/android/service/autofill/FillResponse.Builder#addDataset(android.service.autofill.Dataset)

    【讨论】:

      猜你喜欢
      • 2018-07-16
      • 1970-01-01
      • 2018-07-02
      • 2022-01-23
      • 2019-12-26
      • 1970-01-01
      • 2021-01-06
      • 2015-02-07
      • 2019-03-01
      相关资源
      最近更新 更多