簡體   English   中英

Android 如何檢測自動填充按下?

[英]Android How can I detect autofill pressed?

我使用 AutofillManager https://developer.android.com/reference/android/view/autofill/AutofillManager並且無法理解我如何檢測用戶自己輸入值還是用戶 Z99938282F04071859941E18F 任何自動填充選項。 我嘗試使用editText.autofillValue但它在兩種情況下都包含值

任何人都知道我該如何解決它? 請幫幫我!)

PS代碼

我有 function 請求自動填充

fun allowAutoFill(view: View?) {
        if (view != null) {
            val afm = requireContext().getSystemService(AutofillManager::class.java)
            if (afm.isAutofillSupported && afm.isEnabled) {
                afm?.requestAutofill(view)
            }
        }
    }

之后我想知道用戶從自動填充中輸入了一些東西或 select 值。 分析需要它。

private fun isAutoFillApplied() = binding?.editPassword?.autofillValue?.textValue?.isNotEmpty() == true

但是binding?.editPassword?.autofillValue包含值,如果用戶輸入某些內容並且如果用戶 select 自動填充選項

我找不到很酷的答案,所以我使用了糟糕的骯臟技巧。 我在屏幕上有兩個edittext。 如果用戶 select 任何自動填充選項,此編輯文本會同時填充。 因此,如果文本的時間差變化不大,我isAutofill值填充為true 這真的不是很好的解決方案,但我找不到另一個。

這看起來像這樣

var lastChangedTime = 0L
var isAutoFill = false
var lastRepeatPassword: String? = null

editPassword.addTextChangedListener { text ->
                lastChangedTime = System.currentTimeMillis()
}

editRepeatPassword.addTextChangedListener { text ->
               if (text.toString() != lastRepeatPassword) {
                   lastRepeatPassword = text.toString()
                   isAutoFill = (System.currentTimeMillis() - lastChangedTime) < 50
               }
           }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM