onActivityResult 方法返回 RESULT_CANCELED 错误?

时间:2021-06-08 22:28:47

标签: java android android-keystore google-fit google-fit-api

我正在尝试为大学项目设置 Google Fit API,但是我刚刚注意到在选择 Google 登录 RESULT_CANCELED 后出现错误。

我阅读了其他一些论坛页面并尝试了一些解决方案:

  • 将密钥库更改为发布模式,而不是调试
  • 更改依赖项
  • 更改密钥库签名配置

没有什么对我有用!我不知道我做错了什么,所以请向我提问,我很乐意提供帮助。我知道我正在使用已弃用的 API 函数,但是我找不到任何我了解如何实施的最新信息。

研究了堆栈溢出答案:
Google Fit O Auth fails with RESULT_CANCELED without showing permission page
Google Oauth 2.0 RESULT_CANCELED while using Google Fit api

构建器

        mApiClient = new GoogleApiClient.Builder(this)
                .addApi(Fitness.SENSORS_API)
                .addApi(Fitness.RECORDING_API)
                .addApi(Fitness.HISTORY_API)
                .addApi(Fitness.SESSIONS_API)
                .addApi(Fitness.GOALS_API)
                .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }

方法

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_OAUTH) {
        authInProgress = false;
        if (resultCode == RESULT_OK) {
            if (!mApiClient.isConnecting() && !mApiClient.isConnected()) {
                mApiClient.connect();
            }
        } else if (resultCode == RESULT_CANCELED) {
            Log.e("GoogleFit", "RESULT_CANCELED");
        }
    } else {
        Log.e("GoogleFit", "requestCode NOT request_oauth");
    }
}

配置

  release {
        storeFile file("C:\\Program Files\\Java\\jdk1.8.0_144\\bin")
        storePassword "pw"
        keyAlias "release"
        keyPassword "pw"
    }

0 个答案:

没有答案