I am creating application which can use google fit api. I want to get all the activities(Movements) available in the google fit. Here the list of activities in google fit
Had similar problem when started playing with Google Fit API on Android.
There are videos with code samples as well as more detailed API documentation on Google Fit website.
It helped me a lot -- https://developers.google.com/fit/android/get-started
Check both videos and later how to save and get data types:
https://developers.google.com/fit/android/data-types
To have some data available install Google Fit app on your android phone. Use it for a while and then you will have some real data in Google Fit database available.
EDIT:
If I get your edited question correctly, then you need something like the following code. Please note that I use this in my own app that lists activities recorded by Google Fit Andorid app. I'm not sure if it will list other activities, for example custom data types recorded by other apps.
Request "activites" (like STILL, RUNNING, WALKING) from Google Fit:
DataReadRequest readRequest = new DataReadRequest.Builder()
.read(DataType.TYPE_ACTIVITY_SEGMENT)
// maybe you want to limit data to specific time range?
//.setTimeRange(today.startTime, today.endTime, TimeUnit.MILLISECONDS)
.build();
Then parse the response. While parsing there will be activity time available:
Fitness.HistoryApi.readData(mClient, readRequest).setResultCallback(new ResultCallback<DataReadResult>() {
@Override
public void onResult(DataReadResult dataReadResult) {
for (DataSet dataSet : dataReadResult.getDataSets()) {
for (DataPoint dataPoint : dataSet.getDataPoints()) {
DataType dataType = dataPoint.getDataType();
if (dataType.equals(DataType.TYPE_ACTIVITY_SEGMENT)) {
String activity = FitnessActivities.getValue(dataPoint);
/* process as needed */
/* the `activitity' string contains values as described here:
* https://developer.android.com/reference/com/google/android/gms/fitness/FitnessActivities.html
*/
}
}
}
}
});
Like I said it works for me -- in my own app I list activities (and their type, ie. walking, running, etc) recorded by Google Fit app for Android.
Hope this can help others...
List<Session> sessions = sessionReadResponse.getSessions();
for (Session session : sessions) {
dumpSession(session);
Log.i(TAG, "Activity Name: "+sessions.get(position).getActivity());
position++;
List<DataSet> dataSets = sessionReadResponse.getDataSet(session);
for (DataSet dataSet : dataSets) {
dumpDataSet(dataSet);
}
}
The Google Fit activities are listed in the FitnessActivities class.
You can programmatically get a list of all these fields using:
FitnessActivities.class.getFields()