3

独自の Authenticator を作成し、それを 2 つの異なるアプリ (A と B) のライブラリとして使用しようとしています。 android-authenticator/ . アプリ A をインストールしてからアプリ B をインストールしました。アプリ A が AccountManager.addAccount() を呼び出すと、AccountAuthenticatorActivity が開きます。アプリ B が AccountManager.addAccount() を呼び出すと、何も起こりません。アプリ A をアンインストールしてアプリ B で再試行すると、AccountAuthenticatorActivity が開きます。

私の目標は、2 つのアプリに同じ AccountAuthenticatorActivity と AccountAuthenticator を使用することですが、一度に 1 つのアプリでしか機能しないようです。

これは、AbstractAccountAuthenticator の addAccount です。

 @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(AccountManager.KEY_INTENT, intent);
    return bundle;
}

これは、両方のアプリから accountManager.addAccount() を呼び出す方法です。

 private void addNewAccount(String accountType, String authTokenType) {
    final AccountManagerFuture<Bundle> future = mAccountManager.addAccount(accountType, authTokenType, null, null, this, new AccountManagerCallback<Bundle>() {
        @Override
        public void run(AccountManagerFuture<Bundle> future) {
            try {
                Bundle bnd = future.getResult();

            } catch (Exception e) {
                e.printStackTrace();

            }
        }
    }, null);
}
4

1 に答える 1

4

私は同じ問題を抱えていましたが、このすべての混乱の鍵は AndroidManifest.xml です

カスタム オーセンティケータを作成する方法に関するチュートリアルは、古い (または少なくとも Android Studio 以前) ため、オーセンティケータ ライブラリから、ライブラリを使用するすべてのアプリケーションにアクセス許可、アクティビティ、およびサービスをコピーする必要があると述べています Android Studio はすべてのモジュールのマニフェストを自動的にマージするため、ANDROID STUDIOの場合は間違っています。

Android Studio を使用している場合は、オーセンティケーター モジュールでパーミッション、アクティビティ、およびサービスを許可し、アプリケーションでそのモジュールへの依存関係を追加するだけです。

サンプルの AndroidManifest.xml を次に示します。

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:label="@string/auth_app_name"
    android:theme="@style/Holo.Theme.Light.DarkActionBar">

    <activity
        android:name="ro.muerte.modules.auth.MyAuthenticatorActivity"
        android:exported="true"
        android:label="@string/auth_action_login"
        android:windowSoftInputMode="adjustResize|stateVisible"
        android:clearTaskOnLaunch="true" />


    <service
        android:name="ro.muerte.modules.auth.MyAuthenticateService"
        android:exported="true">
        <intent-filter>
            <action android:name="android.accounts.AccountAuthenticator" />
        </intent-filter>
        <meta-data
            android:name="android.accounts.AccountAuthenticator"
            android:resource="@xml/authenticator" />
    </service>

</application>

于 2013-11-01T16:24:01.573 に答える