4

我使用此代码启用启用自动填充服务。

Intent dialogIntent = new Intent(Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE);
        startActivity(dialogIntent);

我得到了下一个例外:

FATAL EXCEPTION: main

Process: com.example.android.autofillframework, PID: 7683
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.autofillframework/com.example.android.autofillframework.app.StandardSignInActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.REQUEST_SET_AUTOFILL_SERVICE }
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.REQUEST_SET_AUTOFILL_SERVICE }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1936)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1615)
at android.app.Activity.startActivityForResult(Activity.java:4472)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:65)
at android.app.Activity.startActivityForResult(Activity.java:4430)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:711)
at android.app.Activity.startActivity(Activity.java:4791)
at android.app.Activity.startActivity(Activity.java:4759)
at com.example.android.autofillframework.app.StandardSignInActivity.onCreate(StandardSignInActivity.java:53)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6541) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
4

3 回答 3

5

您在意图中缺少包名称。从javadoc

输入:Intent 的数据 URI 设置为应用程序名称,使用“包”模式(如“package:com.my.app”)。

于 2017-09-07T19:53:28.740 回答
4

您在意图中缺少包名称。在 intent.setData() 中传递您的应用程序包名称。喜欢:

Intent intent = new Intent(android.provider.Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE);
intent.setData(Uri.parse("package:<YOUR_APP_PACKAGE_NAME>"));
startActivity(intent)
于 2020-01-22T07:24:50.423 回答
3

在华为设备上,如果您正确检查 hasEnabledAutofillServices() 和 isAutofillSupported() 并且包含该软件包,似乎甚至会发生这种情况。

于 2018-02-09T08:57:03.530 回答