Created
April 21, 2015 17:57
-
-
Save rsteckler/f4f24231d11f3e02a226 to your computer and use it in GitHub Desktop.
Delete data from Google Fit account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Requires OAuth2 permissions to read/write fitness data. | |
private void deleteAllCalories() { | |
//Set the delete timespan to be the last year | |
Calendar cal = Calendar.getInstance(); | |
Date now = new Date(); | |
cal.setTime(now); | |
long endTime = cal.getTimeInMillis(); | |
cal.add(Calendar.YEAR, -1); | |
long startTime = cal.getTimeInMillis(); | |
// Create a delete request object, providing a data type and a time interval | |
DataDeleteRequest request = new DataDeleteRequest.Builder() | |
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS) | |
.addDataType(DataType.TYPE_CALORIES_EXPENDED) | |
.build(); | |
// Invoke the History API with the Google API client object and delete request, and then | |
// specify a callback that will check the result. | |
Fitness.HistoryApi.deleteData(mGoogleApiFitnessClient, request) | |
.await(1, TimeUnit.MINUTES); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment