【问题标题】:Signing out of GoogleFit退出 Google 健身
【发布时间】:2023-03-20 19:10:01
【问题描述】:

我曾尝试使用this,但推荐的没有任何作用:

Fitness.getConfigClient(this, GoogleSignIn.getLastSignedInAccount(this)).disableFit()

我如何通过 Google 进行身份验证:

if (!GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(this), fitnessOptions)) {
        GoogleSignIn.requestPermissions(this, REQUEST_OAUTH_REQUEST_CODE,
                GoogleSignIn.getLastSignedInAccount(this),
                fitnessOptions);
    } else {
        subscribe();
    }



@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == REQUEST_OAUTH_REQUEST_CODE) {
                subscribe();
            }
        }
    }



public void subscribe() {
        
        Fitness.getRecordingClient(this, GoogleSignIn.getLastSignedInAccount(this))
                .subscribe(DataType.TYPE_STEP_COUNT_CUMULATIVE)
                .addOnCompleteListener(
                        new OnCompleteListener<Void>() {
                            @Override
                            public void onComplete(@NonNull Task<Void> task) {
                                if (task.isSuccessful()) {
                                    Log.i(TAG, "Successfully subscribed!");
                                } else {
                                    Log.w(TAG, "There was a problem subscribing.", task.getException());
                                }
                            }
                        });
    }

我需要能够获取上次登录的 google 帐户,并为用户提供退出其 google 帐户的选项。

【问题讨论】:

    标签: java android-studio google-fit


    【解决方案1】:

    要断开 Google 帐户与您的应用的连接,您应该使用 GoogleSignIn 中的 signOut 方法,该方法将保留授予的权限,或者您可以使用 revokeAccess 方法进行注销和撤销授予的权限:

    val options = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .addExtension(getFitnessOptions())
        .requestProfile()
        .build()
    
    GoogleSignIn.getClient(this, options).signOut() // or GoogleSignIn.getClient(this, options).revokeAccess()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-27
      相关资源
      最近更新 更多