app/src/main/java/com/google/android/gms/fit/samples/basichistoryapifinal/MainActivity.java
private DataSet insertFitnessData() {
        Log.i(TAG, "Creating a new data insert request.");

        // Set a start and end time for our data, using a start time of 1 hour before this moment.
        Calendar cal = Calendar.getInstance();
        Date now = new Date();
        cal.setTime(now);
        long endTime = cal.getTimeInMillis();
        cal.add(Calendar.HOUR_OF_DAY, -1);
        long startTime = cal.getTimeInMillis();

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

        // Create a data set
        int stepCountDelta = 0;
        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);
        dataSet.add(dataPoint);

        return dataSet;
    }
/*
    Create and return a DataSet of step count data for insertion using the History API.
     */
Create and return a DataSet of step count data for insertion using the History API.
Create and return a DataSet of step count data for insertion using the History API .
private DataSet insertFitnessData() {
        Log.i(TAG, "Creating a new data insert request.");
        Calendar cal = Calendar.getInstance();
        Date now = new Date();
        cal.setTime(now);
        long endTime = cal.getTimeInMillis();
        cal.add(Calendar.HOUR_OF_DAY, -1);
        long startTime = cal.getTimeInMillis();
        DataSource dataSource = new DataSource.Builder()
                .setAppPackageName(this)
                .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
                .setStreamName(TAG + " - step count")
                .setType(DataSource.TYPE_RAW)
                .build();
        int stepCountDelta = 0;
        DataSet dataSet = DataSet.create(dataSource);
        DataPoint dataPoint = dataSet.createDataPoint()
                .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS);
        dataPoint.getValue(Field.FIELD_STEPS).setInt(stepCountDelta);
        dataSet.add(dataPoint);
        return dataSet;
    }
private DataSet insertFitnessData ( ) { Log . i ( TAG , "Creating a new data insert request." ) ; Calendar cal = Calendar . getInstance ( ) ; Date now = new Date ( ) ; cal . setTime ( now ) ; long endTime = cal . getTimeInMillis ( ) ; cal . add ( Calendar . HOUR_OF_DAY , - 1 ) ; long startTime = cal . getTimeInMillis ( ) ; DataSource dataSource = new DataSource . Builder ( ) . setAppPackageName ( this ) . setDataType ( DataType . TYPE_STEP_COUNT_DELTA ) . setStreamName ( TAG + " - step count" ) . setType ( DataSource . TYPE_RAW ) . build ( ) ; int stepCountDelta = 0 ; DataSet dataSet = DataSet . create ( dataSource ) ; DataPoint dataPoint = dataSet . createDataPoint ( ) . setTimeInterval ( startTime , endTime , TimeUnit . MILLISECONDS ) ; dataPoint . getValue ( Field . FIELD_STEPS ) . setInt ( stepCountDelta ) ; dataSet . add ( dataPoint ) ; return dataSet ; }
Create and return a DataSet of step count data for insertion using the History API.
Create and return a DataSet of step count data for insertion using the History API .
// Set a start and end time for our data, using a start time of 1 hour before this moment. // Create a data source // Create a data set // For each data point, specify a start time, end time, and the data value -- in this case, // the number of new steps.