Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Primeiros Passos com Google Fit

Primeiros Passos com Google Fit

3 anos de Android Meetup – GDG São Paulo

Douglas Kayama

May 07, 2016
Tweet

More Decks by Douglas Kayama

Other Decks in Technology

Transcript

  1. @douglasdrumond Capacidades • Activity • Heart rate • Location •

    Nutrition • Power • Speed • Weight • Workout • Strength • Weight Lift • Crossfit • Interval Training • High Intensity Interval Training
  2. @douglasdrumond Data type • Tipos de dados, ex: passos, bpm,

    localização • Define um schema • Nome e lista de campos
  3. @douglasdrumond Console do Google • Pegar o SHA1 via keytool

    • Cadastrar novo client ID • Depende do nome do pacote e assinatura
  4. @douglasdrumond Leia dados Fitness.SensorsApi.findDataSources(mClient, new DataSourcesRequest.Builder()
 .setDataTypes(DataType.TYPE_LOCATION_SAMPLE)
 .setDataSourceTypes(DataSource.TYPE_RAW)
 .build())
 .setResultCallback(new

    ResultCallback<…>()
 …
 for (DataSource dataSource : dataSourcesResult.getDataSources()) {
 registerFitnessDataListener(dataSource,
 DataType.TYPE_LOCATION_SAMPLE);
 }
 }
 }
 });
  5. @douglasdrumond registerFitnessDataListener mListener = new OnDataPointListener() {
 public void onDataPoint(DataPoint

    dataPoint) {
 for (Field field : dataPoint.getDataType().getFields()) {
 Value val = dataPoint.getValue(field);
 Log.i(TAG, "Detected DataPoint field: " + field.getName());
 Log.i(TAG, "Detected DataPoint value: " + val);
 }
 }
 };
  6. @douglasdrumond registerFitnessDataListener Fitness.SensorsApi.add(mClient,
 new SensorRequest.Builder()
 .setDataSource(dataSource).setDataType(dataType)
 .setSamplingRate(10, TimeUnit.SECONDS).build(), mListener)
 .setResultCallback(new

    ResultCallback<Status>() {
 @Override
 public void onResult(Status status) {
 if (status.isSuccess()) {Log.i(TAG, "Listener registered!”); } 
 else { Log.i(TAG, "Listener not registered.”); }
 }
 });

  7. @douglasdrumond Alguns exemplos DataSource nutritionSource = new DataSource.Builder() .setDataType(DataType.TYPE_NUTRITION) ...

    .build(); DataPoint banana = DataPoint.create(nutritionSource); banana.setTimestamp(now.getMillis(), TimeUnit.MILLISECONDS); banana.getValue(Field.FIELD_FOOD_ITEM).setString("banana"); banana.getValue(Field.FIELD_MEAL_TYPE).setInt(Field.MEAL_TYPE_SNACK); banana.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_POT ASSIUM, 422f)
  8. @douglasdrumond Tópicos não cobertos • Recording API • History API

    • Sessions API • BLE API • Config API (Custom Data Types)