[英]Save for autofill dialog not showing up
我有一個顯示用戶名 UI 的活動,輸入后點擊繼續按鈕顯示輸入密碼 UI。 輸入密碼並點擊登錄按鈕完成當前活動並啟動新活動。 在我的設備上,我選擇了 Google 自動填充服務,因此在完成第一個活動后我想“保存以供自動填充?” 對話框出現,但事實並非如此。 我通過在我的活動中添加 autofillHints 和任何其他內容來准備我的應用程序。 我應該為彈出的對話框添加任何內容嗎?
盡管遵循文檔並將autofillHints
添加到我的布局中,但我在模擬器上遇到了類似的行為,其中在使用 Google 自動填充服務時調用AutofillManager.commit()
沒有觸發保存 UI。
FWIW,我從模擬器切換到物理設備,即使我沒有對實現進行任何更改,保存 UI 也開始正確觸發。 在這兩種情況下,我都登錄了 Google 帳戶,並且在這兩種情況下,Google 的示例調試自動填充服務都正確觸發了保存 UI。
我注意到您說的是“設備”,所以也許這不適用於您,但如果您使用模擬器,那么在物理設備上進行測試可能值得一試,而且似乎沒有其他解釋為什么它不會'不顯示。
我遇到了與您的情況類似的問題,請找到解決方案:
1- 確保您添加了以下權限來清單:
<uses-permission
android:name="android.permission.BIND_AUTOFILL_SERVICE"
tools:ignore="ProtectedPermissions" />
2- 假設在您的登錄屏幕中您有三個EditText
(用戶名、密碼和驗證碼),因此您必須為屏幕中的所有編輯文本添加android:importantForAutofill
。 如果您錯過添加它(例如驗證碼導致不需要保存它),不幸的是,自動填充對話框將不會顯示。
3- 要保存用戶名和密碼,您應該為用戶名 editText 和密碼 editText 添加:
android:importantForAutofill="yes"
對於用戶名 editText,您應該添加:
android:autofillHints="username"
對於密碼editText,您應該添加:
android:autofillHints="password"
注意:您不應該使用textNoSuggestions
作為密碼的文本輸入類型:
android:inputType="textPassword|textNoSuggestions"
取而代之的是,您應該使用:
android:inputType="textPassword"
4-您應該排除不需要的editText(Captcha)以免被保存,因此您應該添加到驗證碼editText:
android:importantForAutofill="noExcludeDescendants"
5-這是代碼片段:
com.google.android.material.textfield.TextInputLayout
android:id="@+id/usernameTextInputLayout"
style="@style/TextInputStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_16"
android:layout_marginEnd="@dimen/margin_16"
android:layout_marginBottom="@dimen/margin_16"
app:endIconDrawable="@drawable/ic_username"
app:endIconMode="custom"
app:endIconTint="?attr/theme_primary">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="username"
android:hint="@string/hint_username"
android:imeOptions="actionNext"
android:importantForAutofill="yes"
android:inputType="text"
android:maxLines="1"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/passwordTextInputLayout"
style="@style/TextInputStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_16"
android:layout_marginEnd="@dimen/margin_16"
android:layout_marginBottom="@dimen/margin_16"
app:endIconDrawable="@drawable/ic_password"
app:endIconMode="custom"
app:endIconTint="?attr/theme_primary">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="password"
android:hint="@string/hint_password"
android:importantForAutofill="yes"
android:inputType="textPassword"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/captchaTextInputLayout"
style="@style/TextInputStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_16"
android:layout_marginEnd="@dimen/margin_16"
android:layout_marginBottom="@dimen/margin_16"
android:importantForAutofill="noExcludeDescendants"
app:boxCornerRadiusTopEnd="0dp"
app:boxCornerRadiusTopStart="0dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/captchaEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_captcha_input"
android:imeOptions="actionNext"
android:importantForAutofill="noExcludeDescendants"
android:inputType="numberDecimal"
android:maxLength="@integer/otp_input_length"
android:maxLines="1"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>
確保在您的設備設置中也啟用了自動填充谷歌: System > Language & Input > Autofill Service > Choose google.
根據設備的不同,它可能位於不同的嵌套設置頁面中。
如果您想創建自定義自動填充,請確保閱讀 API 上的文檔: https : //developer.android.com/guide/topics/text/autofill
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.