如何从Google健身状态检查启用或停用状态

时间:2016-07-06 11:54:45

标签: java android google-fit

当用户停用Google健身时,我希望我的应用检查是否已启用或禁用Google健身状态。我只找到了禁用该应用的代码。

public void disableGoogleFit(){
    if(!mClient.isConnected()){
        Log.e(TAG, "Google Fit wasn't connected");
        return;
    }
    PendingResult<Status> pendingResult = Fitness.ConfigApi.disableFit(mClient);

    pendingResult.setResultCallback(new ResultCallback<Status>() {
        @Override
        public void onResult(Status status) {
            if(status.isSuccess()) {
                Log.i(TAG, "Google Fit disabled");
            }else{
                Log.e(TAG, "Google Fit wasn't disabled " + status);
            }
        }
    });
}

如何检测调用Intent的时间?

1 个答案:

答案 0 :(得分:0)

您可以查看Google的Getting Started文档,以下是文档中的代码示例:

if (mClient == null && checkPermissions()) {
mClient = new GoogleApiClient.Builder(this)
.addApi(Fitness.SENSORS_API)
.addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
.addConnectionCallbacks(
new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
Log.i(TAG, "Connected!!!");
// Now you can make calls to the Fitness APIs.
findFitnessDataSources();
}

这将检查与Google健身的连接。

希望这有帮助!