2015-06-27 109 views
2

我已經寫了一些代碼來添加我的自定義帳戶設置 雖然點擊添加帳戶我可以看到我的自定義帳戶,當點擊時我顯示登錄表單。這裏面我打電話下面的代碼addAccountExplyly成功,但沒有在設置/帳戶中顯示任何帳戶

if (mAccountManager.addAccountExplicitly(account, password, userData)) { 
     // worked 
     System.out.println("Account added"); 
    } else { 
     // guess not 
     System.out.println("NOT DONE"); 
    } 

第一次顯示「添加帳戶」,但不能看到設置/帳戶什麼。 請幫助我。

下面是完整的代碼

Log.d("AuthenticatorActivity", "onCreate"); 

    mAccountManager = AccountManager.get(getBaseContext()); 

    String accountName = getIntent().getStringExtra(ARG_ACCOUNT_NAME); 
    mAuthTokenType = getIntent().getStringExtra(ARG_AUTH_TYPE); 

    if (mAuthTokenType == null) 
     mAuthTokenType = AccountGeneral.AUTHTOKEN_TYPE_FULL_ACCESS; 

    accountName= "test55"; 

    findAccount(accountName); 

    System.out.println(mAuthTokenType + "accountName : " + accountName); 

    Bundle data = new Bundle(); 
    data.putString(AccountManager.KEY_ACCOUNT_NAME, accountName); 
    data.putString(AccountManager.KEY_ACCOUNT_TYPE, mAuthTokenType); 
    data.putString(AccountManager.KEY_AUTHTOKEN, authtoken); 
    data.putString(PARAM_USER_PASS, password); 

    Bundle userData = new Bundle(); 
    userData.putString("userObjectId", "2"); 
    data.putBundle(AccountManager.KEY_USERDATA, userData); 

    final Intent res = new Intent(); 
    res.putExtras(data); 

    final Account account = new Account(accountName, "com.coderzheaven.auth_example"); 

    if (mAccountManager.addAccountExplicitly(account, password, userData)) { 
     // worked 
     System.out.println("DONE"); 
    } else { 
     // guess not 
     System.out.println("NOT DONE"); 
    } 

    mAccountManager.addAccountExplicitly(account, password, userData); 
    mAccountManager.setAuthToken(account, mAuthTokenType, authtoken); 
    setAccountAuthenticatorResult(data); 
    setResult(RESULT_OK, res); 
+0

您的登錄形式應該是AccountAuthenticatorActivity'的'一個子類,否則將不顯示上設置 – chip

回答

0

我注意到你發送的帳戶類型錯誤的值。該值需要與authenticator.xml中的android:accountType匹配。

data.putString(AccountManager.KEY_ACCOUNT_TYPE,mAuthTokenType);

6

我有同樣的問題,並發現,當機器人:標籤字段中authenticator.xml(或任何XML文件你指着在AndroidManifest.xml您的認證服務定義)不包含一個本地化的字符串的帳戶不會顯示在設置下。

即,這不起作用: 機器人:標籤= 「我的應用」

但確實: 機器人:標籤= 「@字符串/ my_app應用」

+3

感謝的人,真正起作用,那是很愚蠢的,花了我一個工作日......不是關於這個問題的一個字android的文檔! –

0

儘量正確地檢查,如果你在AndroidManifest文件中填寫有關SyncService和SyncAdapter的數據。這對我有幫助。

這一個在清單:

<service android:name=".Model.Sync.SyncService" 
     android:exported="true"> 
     <intent-filter> 
      <action android:name="android.content.SyncAdapter" /> 
     </intent-filter> 
     <meta-data android:name="android.content.SyncAdapter" 
      android:resource="@xml/syncadapter" /> 
    </service> 

而這一次在syncadapter.xml:

<?xml version="1.0" encoding="utf-8"?> 
<sync-adapter 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:contentAuthority="com.example.android.datasync.provider" 
    android:accountType="example.com" 
    android:userVisible="true" 
    android:supportsUploading="true" 
    android:allowParallelSyncs="false" 
    android:isAlwaysSyncable="true"/> 
相關問題