Android app crashes on addAccountExplicitly(account, password, null);

后端 未结 6 1536
伪装坚强ぢ
伪装坚强ぢ 2021-01-03 19:22

After a successful basic authentication I want to add an account for later use. When I tried to create this account using the following code:

AccountManager          


        
相关标签:
6条回答
  • 2021-01-03 20:00

    You are using "com.example" as unique identifier for your app,please check if it's same in "authenticator.xml"

    0 讨论(0)
  • 2021-01-03 20:02

    It may cause by an ACCOUNT_TYPE mismatch. check ACCOUNT_TYPE in Class and ACCOUNT_TYPE in authenticator.xml must match

    private static final String ACCOUNT_TYPE = "com.someonew.syncaccount";
    

    authenticator.xml

     <?xml version="1.0" encoding="utf-8"?>
        <account-authenticator
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:accountType="com.someonew.syncaccount"
            android:icon="@mipmap/ic_launcher_round"
            android:smallIcon="@mipmap/ic_launcher_round"
            android:accountPreferences="@xml/syncsettings"
            android:label="@string/app_name"/>
    
    0 讨论(0)
  • 2021-01-03 20:09

    In my case i was having Package name contains capital characters, so service was not getting registered in Android Manifest and hence issue was occurred.

    android:name="com.SyncServices.SyncService" 
    

    changed to

    android:name="com.syncservices.SyncService"
    
    0 讨论(0)
  • 2021-01-03 20:12

    In my case it was happening that I had another app installed on the device with the same account name and type, but with different signing cert that the one I was trying to install.

    So it was crashing the app.

    Checking the android doc for the method addAccountExplicity, it says:

    This method requires the caller to have a signature match with the authenticator that owns the specified account.

    That was my problem

    0 讨论(0)
  • 2021-01-03 20:12

    There's not a one golden response to your 3rd question.

    If all apps use the same name, you may consider a service, just remember to restrict it to your own apps.

    However, the user may get confused about being signed in just after the app is installed thus I would recommend to allow user to sign in in each separate app. You could generate multiple separate private keys for the the same app in Google Developer Console and thus get the same user LOCAL_ID in every app.

    0 讨论(0)
  • 2021-01-03 20:22

    1) Reason for crash was because the following snippet was missing in AndroidManifest.xml.

    <service android:name="com.example.accounts.GenericAccountService">
        <intent-filter>
             <action android:name="android.accounts.AccountAuthenticator" />
        </intent-filter>
        <meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator" />
    </service>
    

    2) It is absolutely possible, even though best practice example is still missing.

    3) No idea. Yet...

    0 讨论(0)
提交回复
热议问题