如何在 Jetpack Compose 中集成自动填充

问题描述

我想在我的应用程序(电子邮件和密码)中提供一些完全使用 Jetpack compose 编写的自动填充功能。我遇到了 this blog postthis demo code,我都尝试过。不幸的是,在与文本字段交互时,我无法获得任何弹出窗口。

修改我的代码后,我最终使用了提供的演示。一个最小的示例如下所示(ExplicitAutofillTypesDemo 可组合项取自上述演示代码,未经任何修改):

class MainActivity: AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            ExplicitAutofillTypesDemo()
        }
    }
}

我错过了什么?我需要在其他地方启用它吗?官方的 compose autofill documentation 不是很有帮助。我只想在触摸上面博客文章中的文本字段时获得自动填充弹出窗口。

解决方法

就我而言,由于自动填充似乎不适用于除 Google 之外的任何其他提供商,因此没有显示弹出窗口。调试日志显示以下消息:

D/Autofill Status: Autofill popup isn't shown because autofill is not available.
    
    Did you set up autofill?
    1. Go to Settings > System > Languages&input > Advanced > Autofill Service
    2. Pick a service
    
    Did you add an account?
    1. Go to Settings > System > Languages&input > Advanced
    2. Click on the settings icon next to the Autofill Service
    3. Add your account

我以 Microsoft Authenticator 为例进行了尝试,但它不起作用。当我切换到 Google 时,一切都按预期运行。