2016-09-23 8 views
0

一部のデバイスでは、1時間に1回データが取得されます。しかし、別のものでは、私は4分ごとにそれらを取得します。 私はクライアント作る:Google Fitクライアントの状態を取得するにはどうすればよいですか?

client = new GoogleApiClient.Builder(context) 
     .addApi(Fitness.SENSORS_API) 
     .addScope(Fitness.SCOPE_ACTIVITY_READ) 
     .addScope(Fitness.SCOPE_BODY_READ_WRITE) 
     .addScope(Fitness.SCOPE_LOCATION_READ_WRITE) 
     .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ)) 
     .addScope(new Scope(Scopes.FITNESS_BODY_READ_WRITE)) 
     .addScope(new Scope(Scopes.FITNESS_LOCATION_READ_WRITE)) 
     .addConnectionCallbacks(Client.this) 
     .addOnConnectionFailedListener(Client.this) 
     .build(); 

client.connect(); 

次にセンサー:

Fitness.SensorsApi.add(
       client, 
       new SensorRequest.Builder() 
         .setDataSource(dataSource) 
         .setDataType(dataType) 
         .setAccuracyMode(SensorRequest.ACCURACY_MODE_HIGH) 
         .setSamplingRate(5, TimeUnit.SECONDS) 
         .setFastestRate(1, TimeUnit.SECONDS) 
         .setMaxDeliveryLatency(20, TimeUnit.SECONDS) 
         .build(), 
       mListener) 
       .setResultCallback(new ResultCallback<Status>() { 
        @Override 
        public void onResult(Status status) { 
         if (status.isSuccess()) { 
          Log.d("stepsCount", "Listener registered!"); 
         } else { 
          Log.d("stepsCount", "Listener not registered."); 
         } 
        } 
       }); 

そして私は、クライアントの状態を確認したいが、私はあなたがいつもと状態をチェックする方法(

答えて

0

知りませんで与えられたコールバック:

private void buildFitnessClient() { 
    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(); 
          } 

          @Override 
          public void onConnectionSuspended(int i) { 
           // If your connection to the sensor gets lost at some point, 
           // you'll be able to determine the reason and react to it here. 
           if (i == ConnectionCallbacks.CAUSE_NETWORK_LOST) { 
            Log.i(TAG, "Connection lost. Cause: Network Lost."); 
           } else if (i 
             == ConnectionCallbacks.CAUSE_SERVICE_DISCONNECTED) { 
            Log.i(TAG, 
              "Connection lost. Reason: Service Disconnected"); 
           } 
          } 
         } 
       ) 
       .enableAutoManage(this, 0, new GoogleApiClient.OnConnectionFailedListener() { 
        @Override 
        public void onConnectionFailed(ConnectionResult result) { 
         Log.i(TAG, "Google Play services connection failed. Cause: " + 
           result.toString()); 
         Snackbar.make(
           MainActivity.this.findViewById(R.id.main_activity_view), 
           "Exception while connecting to Google Play services: " + 
             result.getErrorMessage(), 
           Snackbar.LENGTH_INDEFINITE).show(); 
        } 
       }) 
       .build(); 
    } 
} 

今すぐ私はリアルタイムであなたのアプリにデータを表示する方法について、Sensors APIとRecording APIを併用しています。

それが役に立てば幸い!

+0

コールバックで状態をチェックできるとは限りません。私はいつでも状態をチェックする必要があります。 – Igor

関連する問題