Android App Crashes of AddAccountExplicitly
Asked Answered
D

1

0

I'm using accountmanager in my application. I check first for an account, to see if it exists. if it does not, it is added explicitly. The Code crashes in addaccountexplicitly()

Account[] accounts = AccountManager.get(this).getAccountsByType(getString(R.string.authtype));
        if(accounts.length==1)
        {
            Toast.makeText(this,accounts[0].name,Toast.LENGTH_SHORT).show();
            Intent i = new Intent(Splash.this, MapsActivity.class);
            startActivity(i);
            finish();
        }
        else
        {
            boolean accountCreated = mAccountManager.addAccountExplicitly(new Account("sasa",getString(R.string.authtype)), "", null);

            Intent i = new Intent(Splash.this, MainActivity.class);
            startActivity(i);
            finish();
        }

Crash Log

    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2464)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
                                                                          at android.app.ActivityThread.access$900(ActivityThread.java:154)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                          at android.os.Looper.loop(Looper.java:224)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5526)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                       Caused by: java.lang.SecurityException: uid 10149 cannot explicitly add accounts of type: com.rakebny.musta.authtype
                                                                          at android.os.Parcel.readException(Parcel.java:1627)
                                                                          at android.os.Parcel.readException(Parcel.java:1579)
                                                                          at android.accounts.IAccountManager$Stub$Proxy.addAccountExplicitly(IAccountManager.java:890)
                                                                          at android.accounts.AccountManager.addAccountExplicitly(AccountManager.java:722)
Defloration answered 20/5, 2016 at 13:46 Comment(4)
Please show your Manifest File so we can examine it and ensure you have specified your authentication service correctly.Uneasy
check manifest permissionDisturbed
Permissions <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />Defloration
@Uneasy iam not using a service is it a must even when using addaccountexplicity() ?Defloration
R
3

In order for the device to handle a custom account type, it must have an authenticator registered for that account type.

Once you have your authenticator, you declare it as a service in the manifest:

        <service
            android:name=".MyAuthenticationService"
            android:exported="false" >
            <intent-filter>
                <action android:name="android.accounts.AccountAuthenticator" />
            </intent-filter>

            <meta-data
                android:name="android.accounts.AccountAuthenticator"
                android:resource="@xml/authenticator" />
        </service>

Then /res/xml/authenticator.xml will tell the system about your account type:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="@string/authtype"
    android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:smallIcon="@drawable/ic_launcher" />

You will also need permission

    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />

Here is the absolute best article on the web for coding a custom Android authenticator: Write your own Android Authenticator

Roadblock answered 20/5, 2016 at 14:10 Comment(1)

© 2022 - 2024 — McMap. All rights reserved.