【发布时间】:2021-10-31 23:36:35
【问题描述】:
我在我的应用中使用自动填充服务。但是这样做有两个问题:
- 单击用户名/密码字段时,演示视图闪烁。有时会出现,有时不会。
- 当我使用 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