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

时间:2016-12-14 09:49:25

标签: android accountmanager google-cloud-print

当我使用Android帐户经理进行帐户前预约时,然后当我选择一个特定帐户时,由于AuthenticatorException,Android应用程序很快停止了

错误:

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)

错误:

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 个答案:

答案 0 :(得分:0)

您必须通过开发控制台注册已签名的应用。这是基于应用程序包名称和sha1指纹的安全措施。

要做到这一点,你必须:

  • 手动或通过Gradle或其他任何方式签署您的APK:Android文档在此步骤中非常清楚。
  • 获取sha1指纹;正如this SO answer中提到的,在Android Studio上很容易:在Gradle面板中,选择根项目下的signingReport任务并运行它 - SHA1指纹将显示在文本输出中。
  • 通过Google开发者控制台注册您的APK:创建一个新的凭据/ OAuth客户端ID / Android,由您获得的SHA1指纹和您的APK包名称定义。

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