android - 如何从 Android 中的 GoogleApiClient 中删除 api 和范围?

标签 android google-api-client android-googleapiclient

在我的应用中,一些 Google API 是可选的。 (在本例中为游戏 API。)

在我的设置 Activity 中,用户可以选择不登录 Google 游戏。我调用那里

Games.signOut(mGoogleApiClient);
googleApiClient.disconnect();
googleApiClient = createGoogleApiClientWithoutGames();
googleApiClient.connect();

createGoogleApiClientWithoutGames 方法创建一个不使用游戏 API 和相应范围的新 GoogleApiClient。

  1. 这是从客户端删除 api 和范围的正确方法吗?

  2. 如何确保其他 Activity (尚未销毁)的 googleApiClient 不使用游戏 API?当前,当从设置 Activity 返回时,客户端正在使用当前客户端配置(使用游戏)在 onStart() 中进行连接。发送本地广播消息并重新创建客户端?

最佳答案

我正在使用一个状态变量来检查 onStart() MainActivity 中的当前客户端是否使用了正确的 api。如果不是,我会在连接之前重新创建它。

完整的源代码可在 https://github.com/friedger/google-api-client-example 获得。

关于android - 如何从 Android 中的 GoogleApiClient 中删除 api 和范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35085725/

相关文章:

android - 有什么方法可以禁用/覆盖 Galaxy Tab 4 上的多任务按钮?

java - 如何清除Glide库本地磁盘缓存

ruby - 使用 Ruby 授权 google drive api

java - 非法参数异常 : GoogleApiClient parameter is required

android - Scope 在 GoogleApiClient 中做什么?

android - GoogleApiClient onConnected 未被调用,在服务中使用

安卓棉花糖 : permissions change for running app

c# - 如何在调试输出窗口中删除不需要的消息 - Xamarin on visual studio

android - 使用 Fused Location Provider 获取启用/禁用的定位服务信息

python - Google API 授权(服务帐户)错误 : HttpAccessTokenRefreshError: unauthorized_client: Unauthorized client or scope in request