com.google.android.gms.fitness.data.DataType Java Examples

The following examples show how to use com.google.android.gms.fitness.data.DataType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Manager.java    From react-native-fitness with MIT License 9 votes vote down vote up
public void subscribeToSteps(Context context, final Promise promise){
    final GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
    if(account == null){
        promise.resolve(false);
        return;
    }
    Fitness.getRecordingClient(context, account)
            .subscribe(DataType.TYPE_STEP_COUNT_DELTA)
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    promise.resolve(true);
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    promise.resolve(false);
                }
            });
}
 
Example #2
Source File: Mission.java    From android-play-games-in-motion with Apache License 2.0 7 votes vote down vote up
@Override
public void onDataPoint(DataPoint dataPoint) {
    // If we get data before the mission has started, discard them.
    if (!mIsStarted) {
        return;
    }
    DataType dataType = dataPoint.getDataType();
    for (Field field : dataType.getFields()) {
        Value val = dataPoint.getValue(field);
        if (dataType.equals(DataType.TYPE_STEP_COUNT_DELTA)) {
            onStepTaken(val.asInt());
        } else if (dataType.equals(DataType.TYPE_SPEED)) {
            // Data comes in as meters per second, have to convert to minutes per mile.
            float speedMetersPerSeconds = val.asFloat();
            updateChallengePace(Utils.metersPerSecondToMinutesPerMile(speedMetersPerSeconds));
        }
    }
}
 
Example #3
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    DataSourcesRequest dataSourceRequest = new DataSourcesRequest.Builder()
            .setDataTypes( DataType.TYPE_STEP_COUNT_CUMULATIVE )
            .setDataSourceTypes( DataSource.TYPE_RAW )
            .build();

    ResultCallback<DataSourcesResult> dataSourcesResultCallback = new ResultCallback<DataSourcesResult>() {
        @Override
        public void onResult(DataSourcesResult dataSourcesResult) {
            for( DataSource dataSource : dataSourcesResult.getDataSources() ) {
                if( DataType.TYPE_STEP_COUNT_CUMULATIVE.equals( dataSource.getDataType() ) ) {
                    registerFitnessDataListener(dataSource, DataType.TYPE_STEP_COUNT_CUMULATIVE);
                }
            }
        }
    };

    Fitness.SensorsApi.findDataSources(mApiClient, dataSourceRequest)
            .setResultCallback(dataSourcesResultCallback);
}
 
Example #4
Source File: BodyHistory.java    From react-native-google-fit with MIT License 6 votes vote down vote up
/**
 * This method creates a dataset object to be able to insert data in google fit
 * @param dataType DataType Fitness Data Type object
 * @param dataSourceType int Data Source Id. For example, DataSource.TYPE_RAW
 * @param value Object Values for the fitness data. They must be int or float
 * @param startTime long Time when the fitness activity started
 * @param endTime long Time when the fitness activity finished
 * @param timeUnit TimeUnit Time unit in which period is expressed
 * @return
 */
private DataSet createDataForRequest(DataType dataType, int dataSourceType, Double value,
                                     long startTime, long endTime, TimeUnit timeUnit) {
    DataSource dataSource = new DataSource.Builder()
            .setAppPackageName(GoogleFitPackage.PACKAGE_NAME)
            .setDataType(dataType)
            .setType(dataSourceType)
            .build();

    DataSet dataSet = DataSet.create(dataSource);
    DataPoint dataPoint = dataSet.createDataPoint().setTimeInterval(startTime, endTime, timeUnit);

    float f1 = Float.valueOf(value.toString());
    dataPoint = dataPoint.setFloatValues(f1);

    dataSet.add(dataPoint);

    return dataSet;
}
 
Example #5
Source File: GoogleFitModule.java    From react-native-google-fitness with MIT License 6 votes vote down vote up
@ReactMethod
public void history_readDailyTotal(String jsonStatement, final Promise promise) {
    try {
        DataType dataType = (DataType) StatementFactory
                .fromJson(jsonStatement)
                .execute(new JavaContext(), null);

        getHistoryClient()
                .readDailyTotal(dataType)
                .addOnFailureListener(new SimpleFailureListener(promise))
                .addOnSuccessListener(new OnSuccessListener<DataSet>() {
                    @Override
                    public void onSuccess(DataSet dataSet) {
                        promise.resolve(JSONEncoder.convertDataSet(dataSet));
                    }
                });

    } catch (Exception e) {
        Log.e(TAG, "Error in history_readDailyTotal()", e);
        promise.reject(e);
    }
}
 
Example #6
Source File: GoogleFitModule.java    From react-native-google-fitness with MIT License 6 votes vote down vote up
@ReactMethod
public void history_readDailyTotalFromLocalDevice(String jsonStatement, final Promise promise) {
    try {
        DataType dataType = (DataType) StatementFactory
                .fromJson(jsonStatement)
                .execute(new JavaContext(), null);

        getHistoryClient()
                .readDailyTotalFromLocalDevice(dataType)
                .addOnFailureListener(new SimpleFailureListener(promise))
                .addOnSuccessListener(new OnSuccessListener<DataSet>() {
                    @Override
                    public void onSuccess(DataSet dataSet) {
                        promise.resolve(JSONEncoder.convertDataSet(dataSet));
                    }
                });

    } catch (Exception e) {
        Log.e(TAG, "Error in history_readDailyTotal()", e);
        promise.reject(e);
    }
}
 
Example #7
Source File: HeartrateHistory.java    From react-native-google-fit with MIT License 6 votes vote down vote up
/**
 * This method creates a dataset object to be able to insert data in google fit
 * @param dataType DataType Fitness Data Type object
 * @param dataSourceType int Data Source Id. For example, DataSource.TYPE_RAW
 * @param value Object Values for the fitness data. They must be int or float
 * @param startTime long Time when the fitness activity started
 * @param endTime long Time when the fitness activity finished
 * @param timeUnit TimeUnit Time unit in which period is expressed
 * @return
 */
private DataSet createDataForRequest(DataType dataType, int dataSourceType, Double value,
                                     long startTime, long endTime, TimeUnit timeUnit) {
    DataSource dataSource = new DataSource.Builder()
            .setAppPackageName(GoogleFitPackage.PACKAGE_NAME)
            .setDataType(dataType)
            .setType(dataSourceType)
            .build();

    DataSet dataSet = DataSet.create(dataSource);
    DataPoint dataPoint = dataSet.createDataPoint().setTimeInterval(startTime, endTime, timeUnit);

    float f1 = Float.valueOf(value.toString());
    dataPoint = dataPoint.setFloatValues(f1);

    dataSet.add(dataPoint);

    return dataSet;
}
 
Example #8
Source File: StepCounter.java    From react-native-google-fit with MIT License 6 votes vote down vote up
public void findFitnessDataSources() {

        DataSourcesRequest dataSourceRequest = new DataSourcesRequest.Builder()
                .setDataTypes(DataType.TYPE_STEP_COUNT_DELTA, DataType.TYPE_STEP_COUNT_CUMULATIVE)
                .setDataSourceTypes( DataSource.TYPE_DERIVED)
                .build();

        ResultCallback<DataSourcesResult> dataSourcesResultCallback = new ResultCallback<DataSourcesResult>() {
            @Override
            public void onResult(DataSourcesResult dataSourcesResult) {
                for (DataSource dataSource : dataSourcesResult.getDataSources()) {
                    DataType type = dataSource.getDataType();

                    if (DataType.TYPE_STEP_COUNT_DELTA.equals(type)
                            || DataType.TYPE_STEP_COUNT_CUMULATIVE.equals(type)) {
                        Log.i(TAG, "Register Fitness Listener: " + type);
                        registerFitnessDataListener(dataSource, type);//DataType.TYPE_STEP_COUNT_DELTA);
                    }
                }
            }
        };

        Fitness.SensorsApi.findDataSources(googleFitManager.getGoogleApiClient(), dataSourceRequest)
                .setResultCallback(dataSourcesResultCallback);
    }
 
Example #9
Source File: StepCounter.java    From react-native-google-fit with MIT License 6 votes vote down vote up
private void registerFitnessDataListener(DataSource dataSource, DataType dataType) {

        SensorRequest request = new SensorRequest.Builder()
                .setDataSource(dataSource)
                .setDataType(dataType)
                .setSamplingRate(3, TimeUnit.SECONDS)
                .build();

        Fitness.SensorsApi.add(googleFitManager.getGoogleApiClient(), request, this)
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        if (status.isSuccess()) {
                            Log.i(TAG, "SensorApi successfully added");
                        }
                    }
                });
    }
 
Example #10
Source File: StepCounter.java    From react-native-google-fit with MIT License 6 votes vote down vote up
@Override
public void onDataPoint(DataPoint dataPoint) {
    DataType type = dataPoint.getDataType();
    Log.i(TAG, "Detected DataPoint type: " + type);

    for (final Field field : type.getFields()) {
        final Value value = dataPoint.getValue(field);
        Log.i(TAG, "Detected DataPoint field: " + field.getName());
        Log.i(TAG, "Detected DataPoint value: " + value);


   /*     activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(mReactContext.getApplicationContext(), "Field: " + field.getName() + " Value: " + value, Toast.LENGTH_SHORT).show();
            }
        });*/

        if(type.equals(DataType.TYPE_STEP_COUNT_DELTA)) {
            WritableMap map = Arguments.createMap();
            map.putDouble("steps", value.asInt());
            sendEvent(this.mReactContext, "StepChangedEvent", map);
        }

    }
}
 
Example #11
Source File: StepsHelper.java    From drip-steps with Apache License 2.0 6 votes vote down vote up
/**
 * Query to get the num of steps since 00:00 until now
 */
private DataReadRequest queryFitnessData() {
	Calendar cal = Calendar.getInstance();
	Date now = new Date();
	cal.setTime(now);
	long endTime = cal.getTimeInMillis();
	cal.set(Calendar.HOUR_OF_DAY, 0);
	cal.set(Calendar.MINUTE, 0);
	cal.set(Calendar.SECOND, 0);
	cal.set(Calendar.MILLISECOND, 0);
	long startTime = cal.getTimeInMillis();

	return new DataReadRequest.Builder()
			.aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
			.bucketByTime(1, TimeUnit.DAYS)
			.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
			.build();
}
 
Example #12
Source File: GoogleFit.java    From cordova-plugin-googlefit with MIT License 6 votes vote down vote up
private void initDataTypes() {
    DataTypeLookup = new HashMap<String, DataType>();
    DataTypeRLookup = new HashMap<DataType, String>();
    TimeUnitLookup = new HashMap<String, TimeUnit>();
    TimeUnitRLookup = new HashMap<TimeUnit, String>();

    for(DataType d : AllData) {
        fillDataTypes(d);
    }

    fillTimeUnit(TimeUnit.DAYS);
    fillTimeUnit(TimeUnit.HOURS);
    fillTimeUnit(TimeUnit.MINUTES);
    fillTimeUnit(TimeUnit.SECONDS);
    fillTimeUnit(TimeUnit.MILLISECONDS);

}
 
Example #13
Source File: GoogleFit.java    From cordova-plugin-googlefit with MIT License 6 votes vote down vote up
/**
 * Converts the types descriptors into a List<DataType>
 * @param types the type names with inverse URL notation, e.g. com.google.activity.summary
 * @return the datatypes as List<DataType>
 */
public List<DataType> JSON2DataType(JSONArray types) {
    ArrayList<DataType> list = new ArrayList<DataType>();

    try {
        for(int i=0; i< types.length(); i++) {
            DataType t = DataTypeLookup.get(types.getString(i));
            if (t!=null) {
                list.add(t);
            }
        }
    } catch (JSONException e) { e.printStackTrace();
    }

    return list;
}
 
Example #14
Source File: GoogleFit.java    From cordova-plugin-googlefit with MIT License 6 votes vote down vote up
private void initDataTypes() {
    DataTypeLookup = new HashMap<String, DataType>();
    DataTypeRLookup = new HashMap<DataType, String>();
    TimeUnitLookup = new HashMap<String, TimeUnit>();
    TimeUnitRLookup = new HashMap<TimeUnit, String>();

    for(DataType d : AllData) {
        fillDataTypes(d);
    }

    fillTimeUnit(TimeUnit.DAYS);
    fillTimeUnit(TimeUnit.HOURS);
    fillTimeUnit(TimeUnit.MINUTES);
    fillTimeUnit(TimeUnit.SECONDS);
    fillTimeUnit(TimeUnit.MILLISECONDS);

}
 
Example #15
Source File: GoogleFit.java    From cordova-plugin-googlefit with MIT License 6 votes vote down vote up
/**
 * Converts the types descriptors into a List<DataType>
 * @param types the type names with inverse URL notation, e.g. com.google.activity.summary
 * @return the datatypes as List<DataType>
 */
public List<DataType> JSON2DataType(JSONArray types) {
    ArrayList<DataType> list = new ArrayList<DataType>();

    try {
        for(int i=0; i< types.length(); i++) {
            DataType t = DataTypeLookup.get(types.getString(i));
            if (t!=null) {
                list.add(t);
            }
        }
    } catch (JSONException e) { e.printStackTrace();
    }

    return list;
}
 
Example #16
Source File: GoogleFit.java    From cordova-plugin-googlefit with MIT License 6 votes vote down vote up
/**
 * Return a {@link DataReadRequest} for all step count changes in the past week.
 */
private DataReadRequest queryDataWithBuckets(long startTime, long endTime, List<DataType> types, List<DataType> aggregations, int duration, TimeUnit time, int bucketType) {

    DataReadRequest.Builder builder = new DataReadRequest.Builder();

    for (int i=0; i< types.size(); i++) {
        builder.aggregate(types.get(i), aggregations.get(i));
    }

    switch (bucketType) {
        case 2:
            builder.bucketByActivitySegment(duration, time);
            break;
        case 1:
            builder.bucketByActivityType(duration, time);
            break;
        case 0:
        default:
            builder.bucketByTime(duration, time);
            break;
    }

    return builder.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS).build();
}
 
Example #17
Source File: DataManager.java    From GoogleFitExample with Apache License 2.0 6 votes vote down vote up
/**
 * Fetch a list of all active subscriptions and log it. Since the logger for this sample
 * also prints to the screen, we can see what is happening in this way.
 */
private void dumpSubscriptionsList() {
    Log.i(TAG, "Dumping subscriptions.");
    // [START list_current_subscriptions]
    Fitness.RecordingApi.listSubscriptions(mClient)
            // Create the callback to retrieve the list of subscriptions asynchronously.
            .setResultCallback(new ResultCallback<ListSubscriptionsResult>() {
                @Override
                public void onResult(ListSubscriptionsResult listSubscriptionsResult) {
                    for (Subscription sc : listSubscriptionsResult.getSubscriptions()) {
                        DataType dt = sc.getDataType();
                        Log.i(TAG, "Active subscription for data type: " + dt.getName());
                    }
                }
            });
    // [END list_current_subscriptions]
}
 
Example #18
Source File: DataQueries.java    From GoogleFitExample with Apache License 2.0 6 votes vote down vote up
/**
 * GET total estimated STEP_COUNT
 *
 * Retrieves an estimated step count.
 *
 */
public static DataReadRequest queryStepEstimate(long startTime, long endTime) {
    DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
            .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
            .setType(DataSource.TYPE_DERIVED)
            .setStreamName("estimated_steps")
            .setAppPackageName("com.google.android.gms")
            .build();

    return new DataReadRequest.Builder()
            .aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
            .bucketByTime(1, TimeUnit.DAYS)
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .enableServerQueries() // Used to retrieve data from cloud
            .build();
}
 
Example #19
Source File: DataQueries.java    From GoogleFitExample with Apache License 2.0 6 votes vote down vote up
/**
 * DataSets can only include one data type.
 *
 * @param startTime Start time for the activity in milliseconds
 * @param endTime End time for the activity in milliseconds
 * @param stepCountDelta Number of steps during the activity
 * @param packageName Package name for the app
 * @return Resulting DataSet
 */
public static DataSet createStepDeltaDataSet(long startTime, long endTime, int stepCountDelta, String packageName, Device device) {

    // Create a data source
    DataSource dataSource = new DataSource.Builder()
            .setAppPackageName(packageName)
            .setDevice(device)
            .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
            .setName(TAG + " - step count")
            .setType(DataSource.TYPE_RAW)
            .build();

    // Create a data set
    DataSet dataSet = DataSet.create(dataSource);
    // For each data point, specify a start time, end time, and the data value -- in this case,
    // the number of new steps.
    DataPoint dataPoint = dataSet.createDataPoint()
            .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
    dataPoint.getValue(Field.FIELD_STEPS).setInt(stepCountDelta); // Can't do this on an Activity Segment
    dataSet.add(dataPoint);

    return dataSet;
}
 
Example #20
Source File: GoogleFit.java    From cordova-plugin-googlefit with MIT License 6 votes vote down vote up
/**
 * Return a {@link DataReadRequest} for all step count changes in the past week.
 */
private DataReadRequest queryDataWithBuckets(long startTime, long endTime, List<DataType> types, List<DataType> aggregations, int duration, TimeUnit time, int bucketType) {

    DataReadRequest.Builder builder = new DataReadRequest.Builder();

    for (int i=0; i< types.size(); i++) {
        builder.aggregate(types.get(i), aggregations.get(i));
    }

    switch (bucketType) {
        case 2:
            builder.bucketByActivitySegment(duration, time);
            break;
        case 1:
            builder.bucketByActivityType(duration, time);
            break;
        case 0:
        default:
            builder.bucketByTime(duration, time);
            break;
    }

    return builder.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS).build();
}
 
Example #21
Source File: DataQueries.java    From GoogleFitExample with Apache License 2.0 6 votes vote down vote up
public static DataSet createActivityDataSet(long startTime, long endTime, String activityName, String packageName, Device device) {

        // Create a data source
        DataSource dataSource = new DataSource.Builder()
                .setAppPackageName(packageName)
                .setDevice(device)
                .setDataType(DataType.TYPE_ACTIVITY_SEGMENT)
                .setName(TAG + " - activity")
                .setType(DataSource.TYPE_RAW)
                .build();

        // Create a data set
        DataSet dataSet = DataSet.create(dataSource);
        // For each data point, specify a start time, end time, and the data value -- in this case,
        // the number of new steps.
        DataPoint activityDataPoint = dataSet.createDataPoint()
                .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
        //dataPoint.getValue(Field.FIELD_STEPS).setInt(stepCountDelta); // Can't do this on an Activity Segment
        activityDataPoint.getValue(Field.FIELD_ACTIVITY).setActivity(activityName);
        dataSet.add(activityDataPoint);

        return dataSet;
    }
 
Example #22
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
private void registerFitnessDataListener(DataSource dataSource, DataType dataType) {

        SensorRequest request = new SensorRequest.Builder()
                .setDataSource( dataSource )
                .setDataType( dataType )
                .setSamplingRate( 3, TimeUnit.SECONDS )
                .build();

        Fitness.SensorsApi.add(mApiClient, request, this)
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        if (status.isSuccess()) {
                            Log.e("GoogleFit", "SensorApi successfully added");
                        } else {
                            Log.e("GoogleFit", "adding status: " + status.getStatusMessage());
                        }
                    }
                });
    }
 
Example #23
Source File: Manager.java    From react-native-fitness with MIT License 6 votes vote down vote up
public void subscribeToActivity(Context context, final Promise promise){
    final GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
    if(account == null){
        promise.resolve(false);
        return;
    }
    Fitness.getRecordingClient(context, account)
            .subscribe(DataType.TYPE_ACTIVITY_SAMPLES)
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    promise.resolve(true);
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    promise.resolve(false);
                }
            });

}
 
Example #24
Source File: RecordingApi.java    From react-native-google-fit with MIT License 5 votes vote down vote up
public void subscribe(ReadableArray dataTypes) {
    ArrayList<String> dataTypesList = new ArrayList<String>();

    for (Object type : dataTypes.toArrayList()) {
        dataTypesList.add(type.toString());
    }


    for (String dataTypeName : dataTypesList) {
        DataType dataType = getDataType(dataTypeName);

        // Just skip unknown data types
        if (dataType == null) {
            continue;
        }

        final String eventName = getEventName(dataTypeName);

        Fitness.RecordingApi.subscribe(googleFitManager.getGoogleApiClient(), dataType)
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(@NonNull Status status) {
                        WritableMap map = Arguments.createMap();

                        map.putString("type", eventName);

                        if (status.isSuccess()) {
                            map.putBoolean("recording", true);
                            Log.i(TAG, "RecordingAPI - Connected");
                            sendEvent(reactContext, eventName, map);
                        } else {
                            map.putBoolean("recording", false);
                            Log.i(TAG, "RecordingAPI - Error connecting");
                            sendEvent(reactContext, eventName, map);
                        }
                    }
                });
    }
}
 
Example #25
Source File: FitDataTypeSetting.java    From android-play-games-in-motion with Apache License 2.0 5 votes vote down vote up
public FitDataTypeSetting(
        boolean required, DataType dataType, long samplingRateSeconds, int accuracyMode) {
    mRequired = required;
    mDataType = dataType;
    mSamplingRateSeconds = samplingRateSeconds;
    mAccuracyMode = accuracyMode;
}
 
Example #26
Source File: DataManager.java    From GoogleFitExample with Apache License 2.0 5 votes vote down vote up
private void listSubscriptions() {
    Fitness.RecordingApi.listSubscriptions(mClient).setResultCallback(new ResultCallback<ListSubscriptionsResult>() {
        @Override
        public void onResult(ListSubscriptionsResult result) {
            for (Subscription sc : result.getSubscriptions()) {
                DataType dt = sc.getDataType();
                Log.i(TAG, "found subscription for data type: " + dt.getName());
            }
        }
    });
}
 
Example #27
Source File: DataManager.java    From GoogleFitExample with Apache License 2.0 5 votes vote down vote up
private void unsubscribeAll() {
    if (isConnected()) {
        Fitness.RecordingApi.listSubscriptions(mClient).setResultCallback(new ResultCallback<ListSubscriptionsResult>() {
            @Override
            public void onResult(ListSubscriptionsResult result) {
                for (Subscription sc : result.getSubscriptions()) {
                    DataType dt = sc.getDataType();
                    Log.i(TAG, "Unsubscribing: " + dt.getName());
                    Fitness.RecordingApi.unsubscribe(mClient, sc)
                            .setResultCallback(new ResultCallback<Status>() {
                                @Override
                                public void onResult(Status status) {
                                    if (status.isSuccess()) {
                                        Log.i(TAG, "Successfully unsubscribed for data type: step count delta");
                                    } else {
                                        // Subscription not removed
                                        Log.i(TAG, "Failed to unsubscribe for data type: step count delta");
                                    }
                                }
                            });
                }
            }
        });
    } else {
        Context context = getApplicationContext();
        if (context != null) {
            Toast.makeText(context, "Error: mClient not connected.", Toast.LENGTH_LONG).show();
        }
    }
}
 
Example #28
Source File: DataQueries.java    From GoogleFitExample with Apache License 2.0 5 votes vote down vote up
/**
 * GET data by ACTIVITY
 *
 * The Google Fit API suggests that we don't want granular data, HOWEVER, we need granular
 * data to do anything remotely interesting with the data. This takes a while so we'll store
 * the results in a local db.
 *
 * After retrieving all activity segments, we go back and ask for step counts for each
 * segment. This allows us to summarize steps and duration per activity.
 *
 */
public static DataReadRequest queryActivitySegment(long startTime, long endTime, boolean isNetworkConnected) {
    if(isNetworkConnected) {
        return new DataReadRequest.Builder()
                .read(DataType.TYPE_ACTIVITY_SEGMENT)
                .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                .enableServerQueries() // Used to retrieve data from cloud.
                .build();
    }else {
        return new DataReadRequest.Builder()
                .read(DataType.TYPE_ACTIVITY_SEGMENT)
                .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                .build();
    }
}
 
Example #29
Source File: DataQueries.java    From GoogleFitExample with Apache License 2.0 5 votes vote down vote up
public static DataReadRequest queryActivitySegmentBucket(long startTime, long endTime) {
    return new DataReadRequest.Builder()
            .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
            .bucketByTime(1, TimeUnit.DAYS)
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .enableServerQueries() // Used to retrieve data from cloud
            .build();
}
 
Example #30
Source File: GoogleApiClientWrapper.java    From android-play-games-in-motion with Apache License 2.0 5 votes vote down vote up
protected void sensorRegistered(DataType dataType) {
    for (FitDataTypeSetting fitDataTypeSetting : sensorsAwaitingRegistration) {
        if (fitDataTypeSetting.getDataType().equals(dataType)) {
            sensorsAwaitingRegistration.remove(fitDataTypeSetting);
            break;
        }

    }
}