无法让我的AccountAuthenticatorActivity在两个不同的应用程序中打开

问题描述:

我试图编写自己的Authenticator并将它用作具有两个不同应用程序的库:A和B. 我已按照此帖发表:http://udinic.wordpress.com/2013/04/24/write-your-own-android-authenticator/。 我安装了应用程序A,然后安装了应用程序B.当应用程序A调用AccountManager.addAccount()时,AccountAuthenticatorActivity打开。当应用程序B调用AccountManager.addAccount()时没有任何事情发生。如果我卸载应用程序A并在应用程序B中再次尝试,则AccountAuthenticatorActivity将打开。无法让我的AccountAuthenticatorActivity在两个不同的应用程序中打开

我的目标是要使用的两个应用程序相同的AccountAuthenticatorActivity和AccountAuthenticator,但它似乎在一个应用程序在同一时间只工作。

这是addAccount我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(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); 
} 

我有同样的问题,关键所有这一切的混乱是AndroidManifest.xml中

教程就如何创建自定义的验证器是一种旧的(或至少前的Android工作室),所以他们指出,您必须将权限,活动和服务从认证程序库复制到所有将要使用该程序库的应用程序中,因为Android Studio会自动合并所有模块的清单。

如果您使用的是Android工作室所有你需要做的是让认证模块中的权限,活动和服务,只需添加一个依赖于应用程序模块。

下面是一个示例的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> 

+1

我错过了 “出口=真” 在我的认证活动的价值。谢谢! – user1787773

+0

很高兴我能帮上忙 –