Android AuthenticatorService正在运行,但帐户设置中没有任何内容

Android AuthenticatorService正在运行,但帐户设置中没有任何内容,android,authentication,accountmanager,android-authenticator,Android,Authentication,Accountmanager,Android Authenticator,我试图在我的应用程序上创建一个自定义帐户类型,这使得我连续十个小时都在尝试 我的推荐信如下: 还有Android开发者的例子 我的步骤是: 创建一个Authenticator类,该类扩展AbstractAccountAuthenticator并重写7个方法 创建AuthenticatorService类,该类扩展了Service类,我在其中初始化Authenticator类 创建AuthenticatorActivity,它扩展了AccountAuthenticatorActivity并在其中

我试图在我的应用程序上创建一个自定义帐户类型,这使得我连续十个小时都在尝试

我的推荐信如下:

还有Android开发者的例子

我的步骤是:

  • 创建一个
    Authenticator
    类,该类扩展
    AbstractAccountAuthenticator
    并重写7个方法
  • 创建
    AuthenticatorService
    类,该类扩展了
    Service
    类,我在其中初始化
    Authenticator
  • 创建
    AuthenticatorActivity
    ,它扩展了
    AccountAuthenticatorActivity
    并在其中创建用户界面以输入凭据
  • AndroidManifest.xml
  • 创建
    @xml/authenticator
    文件并设置信息
  • 所有这些都做得很好,唯一要做的就是找到启动服务的方法。 因此,我创建了另一个活动,并在
    onCreate()
    方法中启动它

    到了测试应用程序的时候了,我决定在emulator(API16)上运行它。
    main活动
    启动,我们可以在运行进程中看到应用程序进程,以及应用程序服务

    所以我去DevTools/AccountsTester插入凭证。。。但这里什么都没有。默认情况下,只有公司和电子邮件应用程序。我认为这是因为模拟器,所以尝试在我的GS3上添加一个帐户,但它是一样的

    在我的logcat中没有错误,我们可以看到服务正在运行(在我的服务类中使用
    Log
    class)

    我的代码与我的第二个参考完全相同,我只是通过返回一个简单的
    true
    来更改服务器请求,因此在我的情况下,服务不使用外部服务器获取有关提交凭据的响应


    我的工作中有没有遗漏的步骤?

    我终于发现了这个小错误。当您使用Android Studio并创建新的XML ressource文件(在本例中为authenticator.XML文件)时,会自动生成一些代码:

    <?xml version="1.0" encoding="utf-8"?>
    <ressources>
    
    </ressources>
    
    我为那些像我一样可能会错过的人提供了这个答案。我还删除了我的
    main活动中的
    startService()
    方法,因为
    AuthenticatorService
    是自动启动的

    <?xml version="1.0" encoding="utf-8"?>
    <account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
        android:accountType="e@string/account_type"
        android:icon="@drawable/myIcon"
        android:smallIcon="@drawable/myIcon"
        android:label="@string/app_name"
        />