添加帐户(设置)方法无法启动Activity

sha*_*anu 5 account android

我想在设置中创建自定义应用帐户.

问题

  1. 有一个图标settings > Add account但没有名称的选项
  2. 单击该(添加帐户)时,AuthenticatorActivity无法启动.我调试Authenticator类,addAccount调用方法但没有弹出任何活动.

我做了以下步骤:

认证类(部分)

public class AccountAuthenticator extends AbstractAccountAuthenticator{
    @Override
    public Bundle addAccount(AccountAuthenticatorResponse response,
            String accountType, String authTokenType,
            String[] requiredFeatures, Bundle options)
            throws NetworkErrorException {
        final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
        intent.putExtra(AuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType);
        intent.putExtra(AuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);
        intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, true);
        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(AccountAuthenticator.KEY_INTENT, intent);
        return bundle;
    }
}
Run Code Online (Sandbox Code Playgroud)

AuthenticatorService

public class AuthenticatorService extends Service{
     @Override
    public IBinder onBind(Intent intent) {
        authenticator = new AccountAuthenticator(this);
        return authenticator.getIBinder();
    }
}
Run Code Online (Sandbox Code Playgroud)

表现

<service android:name="com.voillo.utils.AuthenticatorService" android:exported="false"
            android:label="@string/app_name">
     <intent-filter>
        <action android:name="android.accounts.AccountAuthenticator" />
     </intent-filter>
     <meta-data android:name="android.accounts.AccountAuthenticator"
               android:resource="@xml/authenticator" />
</service>
Run Code Online (Sandbox Code Playgroud)

authenticator xml

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
     android:accountType="com.example.myapp"
     android:icon="@drawable/myapp_icon"
     android:smallIcon="@drawable/myapp_icon_small"
     android:label="myapp"
     />
Run Code Online (Sandbox Code Playgroud)

Les*_*ter 5

您忘记在清单文件上声明活动的可能性很高.我遇到了同样的错误,发现我忘了在项目的清单上声明我的活动.