2016-07-06 57 views
2

當用戶禁用Google健身時,我希望我的應用可以檢查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何時被調用?

回答

0

您可以查看谷歌的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(); 
} 

這將檢查谷歌飛度的連接。

希望這會有所幫助!

相關問題