2016-06-16 10 views
1

내 시계 기능 서비스 (Android Wear)의 Google 피트니스 센서 API에서 위치와 속도를 기록하려고합니다. 여기 내가 사용하는 코드입니다 :Google 피트니스에 데이터 소스가 표시되지 않습니다.

private void connectFitnessDataListeners() { 
    Fitness.SensorsApi.findDataSources(mGoogleApiClient, 
     new DataSourcesRequest.Builder() 
      .setDataTypes(DataType.TYPE_ACTIVITY_SAMPLE) 
      .setDataTypes(DataType.TYPE_LOCATION_SAMPLE) 
      .setDataTypes(DataType.TYPE_SPEED) 
      // Can specify whether data type is raw or derived. 
      .setDataSourceTypes(DataSource.TYPE_RAW) 
      .build()) 
      .setResultCallback(new ResultCallback<DataSourcesResult>() { 
       @Override 
       public void onResult(DataSourcesResult dataSourcesResult) { 
        Log.i(TAG, "Find Data Sources: " + dataSourcesResult.getStatus().toString()); 
        for (DataSource dataSource : dataSourcesResult.getDataSources()) { 
         //only include dataSources from the watch 
         Log.i(TAG, "Data source found: " + dataSource.toString()); 
         Log.i(TAG, String.format("Data Source device %s and type: %s", dataSource.getDevice().toString(),dataSource.getDataType().getName())); 
         if (dataSource.getDevice() != Device.getLocalDevice(getBaseContext())) continue; 

         //FIXME: Turn this into a loop over an array 
         if (dataSource.getDataType().equals(DataType.TYPE_ACTIVITY_SAMPLE) && (mActivitySampleListener == null)) { 
          Log.i(TAG, "Data source for ACTIVITY_SAMPLE found! Registering."); 
          mActivitySampleListener = registerFitnessDataListener(dataSource, DataType.TYPE_ACTIVITY_SAMPLE); 
         } else if (dataSource.getDataType().equals(DataType.TYPE_LOCATION_SAMPLE) && (mLocationSampleListener == null)) { 
          Log.i(TAG, "Data source for LOCATION_SAMPLE found! Registering."); 
          mLocationSampleListener = registerFitnessDataListener(dataSource, DataType.TYPE_ACTIVITY_SAMPLE); 
         } else if (dataSource.getDataType().equals(DataType.TYPE_SPEED) && (mSpeedListener == null)) { 
          Log.i(TAG, "Data source for SPEED found! Registering."); 
          mSpeedListener = registerFitnessDataListener(dataSource, DataType.TYPE_SPEED); 
         } 
        } 
       } 
      } 
    ); 
} 

을하지만, 내가 다른 onConnected 워킹 호출에서이 프로그램을 실행할 때, 내가 for 루프에서 어떤 데이터 소스를 얻을합니다 (Find Data Sources 로그 호출은 성공을 보여줍니다).

나는 무엇을 추구해야 하는가?

UPDATE : 나는 setDataSourceTypes 제한을 제거하면 , 내가 얻을에만이 :

Data source found: DataSource{derived:Application{com.google.android.gms::null}:Device{Sony:SmartWatch 3:15e991d4::3:2}::DataType{com.google.speed[speed(f)]}} 
Data Source device Device{Sony:SmartWatch 3:15e991d4::3:2} and type: com.google.speed 

왜 나는 GPS로부터 위치 정보를 표시되지 않는 이유는 무엇입니까?

답변

0

이것은 내 개발자 오류입니다. setDataTypes는 다양한 데이터 유형을 사용합니다. 내 예제에서는 TYPE_SPEED에 대해서만 데이터 유형을 설정했습니다.