android - 重置 GoogleAuthUtil,以便再次获得许可

标签 android google-play-services

我正在使用 google play 服务身份验证示例 here

如何重置 GoogleAuthUtil 以便它再次请求许可?

它通过抛出提供给对话框的 userRecoverableException 来请求许可。但它只请求一次许可。我需要再次测试请求权限。

我尝试卸载示例应用程序并重新安装示例应用程序,但这没有用它不请求许可似乎它已经知道该应用程序。

protected String fetchToken() throws IOException {
    try {
        return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
    } catch (UserRecoverableAuthException userRecoverableException) {
        // GooglePlayServices.apk is either old, disabled, or not
        // present, which is
        // recoverable, so we need to show the user some UI through the
        // activity.
        MyGooglePlay.handleException(userRecoverableException);
    } catch (GoogleAuthException fatalException) {
        onError("Unrecoverable error " + fatalException.getMessage(),
                fatalException);
    }
    return null;
}


/**
 * This method is a hook for background threads and async tasks that need to provide the
 * user a response UI when an exception occurs.
 */
public void handleException(final Exception e) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (e instanceof GooglePlayServicesAvailabilityException) {
                // The Google Play services APK is old, disabled, or not present.
                // Show a dialog created by Google Play services that allows
                // the user to update the APK
                int statusCode = ((GooglePlayServicesAvailabilityException)e)
                        .getConnectionStatusCode();
                Dialog dialog = GooglePlayServicesUtil.getErrorDialog(statusCode,
                        HelloActivity.this,
                        REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
                dialog.show();
            } else if (e instanceof UserRecoverableAuthException) {
                // Unable to authenticate, such as when the user has not yet granted
                // the app access to the account, but the user can fix this.
                // Forward the user to an activity in Google Play services.
                Intent intent = ((UserRecoverableAuthException)e).getIntent();
                startActivityForResult(intent,
                        REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
            }
        }
    });
}

最佳答案

您可以按照以下步骤使用 Google 设置 应用取消对连接的应用程序的授权:

  1. 启动 Google 设置应用

Google Settings App Icon

  1. 选择已连接的应用选项(在顶部)

Google Settings options

  1. 显示连接的应用程序列表;找到您要取消授权的应用程序并选择它。抱歉,没有屏幕截图,因为我无法从它的 ATM 中删除个人信息 - 但在这里做什么应该非常简单:)

  2. 最后,点击应用详情页面的Disconnect按钮(在底部)

Connected app details

请注意,应用程序取消授权可能需要一些时间。

关于android - 重置 GoogleAuthUtil,以便再次获得许可,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26245204/

相关文章:

android - 当软键盘出现时,如何防止 Android webview 中的固定页脚覆盖输入字段?

android - 如何从 PreferenceActivity 调用特定的 PreferenceFragment?

java - ':app:dexDebug'. gradle failed 'C:\Program Files\Java\jdk1.7.0_51\bin\java.exe' '以非零退出值 2 完成

android - 我们应该将 google 的安全提供程序与 OkHttp 一起使用吗?

android - 我们可以在 android 小部件中显示广告吗

java - 如何在新类中将方法名称设置为参数?

android - 无法获取当前设备位置

android - SMS Retriever API 的依赖关系

android - AppStateClient loadState 检索空字节

android - play-services-ads 与 appcompat 冲突