Android : java.lang.RuntimeException: android.accounts.AuthenticatorException: UNREGISTERED_ON_API_CONSOLE

980 views Asked by At

when i am using android account manager for pre account slelection and then when i am selecting an specific account then Android Application unfortunately stopped because of AuthenticatorException

Error:

12-14 15:08:19.410: E/AndroidRuntime(11571): java.lang.RuntimeException: android.accounts.AuthenticatorException: UNREGISTERED_ON_API_CONSOLE
12-14 15:08:19.410: E/AndroidRuntime(11571):    at com.ibdtd.cloudprinter.MainActivity$OnTokenAcquired.run(MainActivity.java:525)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at android.accounts.AccountManager$11.run(AccountManager.java:1438)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at android.os.Handler.handleCallback(Handler.java:733)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at android.os.Handler.dispatchMessage(Handler.java:95)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at android.os.Looper.loop(Looper.java:146)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at android.app.ActivityThread.main(ActivityThread.java:5602)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at java.lang.reflect.Method.invokeNative(Native Method)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at java.lang.reflect.Method.invoke(Method.java:515)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at dalvik.system.NativeStart.main(Native Method)
12-14 15:08:19.410: E/AndroidRuntime(11571): Caused by: android.accounts.AuthenticatorException: UNREGISTERED_ON_API_CONSOLE
12-14 15:08:19.410: E/AndroidRuntime(11571):    at android.accounts.AccountManager.convertErrorToException(AccountManager.java:1737)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at android.accounts.AccountManager.access$400(AccountManager.java:145)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at android.accounts.AccountManager$AmsTask$Response.onError(AccountManager.java:1583)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at android.accounts.IAccountManagerResponse$Stub.onTransact(IAccountManagerResponse.java:69)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at android.os.Binder.execTransact(Binder.java:404)
12-14 15:08:19.410: E/AndroidRuntime(11571):    at dalvik.system.NativeStart.run(Native Method)

Error at:

private class OnTokenAcquired implements AccountManagerCallback<Bundle> {

    @Override
    public void run(AccountManagerFuture<Bundle> result) {
        try {

            Bundle bundle = result.getResult();
            Intent launch = (Intent) bundle.get(AccountManager.KEY_INTENT);

            if (launch != null) {
                startActivityForResult(launch, AUTHORIZATION_CODE);
            } else {
                String token = bundle
                        .getString(AccountManager.KEY_AUTHTOKEN);

                authPreferences.setToken(token);
                Log.e("AuthApp", authPreferences.getToken());

            }
        } 
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
    }
}
1

There are 1 answers

0
prsandroid On

You have to register your signed app through the dev console. It's a security measure based on the app package name and the sha1 fingerprint.

To do that, you have to:

  • Sign your APK, manually or through Gradle or whatever: the Android documentation is pretty clear on this step.
  • Get your sha1 fingerprint; as mention in this SO answer, it's kind of easy on Android Studio: in the Gradle panel, select the signingReport task under your root project and run it - the SHA1 fingerprint will show in the text output.
  • Register your APK through the Google dev console: create a new Credentials / OAuth client id / Android, defined by the SHA1 fingerprint you got and your APK package name.

https://developers.google.com/drive/android/auth