I am working on demo application to get current activity sample using Google Fit. I can get Speed as well as Distance correctly. But it is not returning "in_vehicle" or "biking" state very frequently though I was in the same state. Find attached screenshot for the same. I got speed 59.40KM/H(36.91 M/h) and at that time it not returned "in_vehicle" activity state.
Please provide solution/feedback for the same.
Code :
@Override
public void onDataPoint(DataPoint dataPoint) {
for (Field field : dataPoint.getDataType().getFields()) {
Value val = dataPoint.getValue(field);
if(field.getName().trim().toLowerCase().equals("activity"))
{
if(FitnessActivities.getName(Integer.parseInt(val.toString())).equals("biking"))
{
strState = "Cycling";
}
else if(FitnessActivities.getName(Integer.parseInt(val.toString())).equals("in_vehicle"))
{
strState = "Automotive";
}
else if(FitnessActivities.getName(Integer.parseInt(val.toString())).equals("walking"))
{
strState = "Walking";
}
else
{
strState = "Not Moving";
}
}
}
}
Thanks.
As you said you are getting speed correctly. You can put customise code written below.
if (strState.equals("Automotive") && speed == 0.00)
{
strState = "Not Moving";
}
else if (strState.equals("Not Moving") && speed > 5)
{
strState = "Automotive";
}
else
{
strState = "strState";
}
This might not be the correct one but It will be give you nearby state result.