The walkingOrRunning() method provided by emil10001 works, however it will not be able to get the activity(running or walking) with the highest confidence, this because, the condition of the second if clause in his for loop always compares the activity's confidence to 0.
To clarify this, let assume we pass a List of size 2 "probableActivities" as argument to the walkingOrRunning() method i.e: we call walkingOrRunning(probableActivities).
Supposing,
List probableActivities = [ activity1, activity2 ],
where:
activity1 = "walking" with 75% confidence
activity2 = "running" 5% confidence.
In brief, the excution of the method walkingOrRunning(probableActivities) is as follows:
1)After the 1st iteration of the for loop, myActivity = "walking"
2)After the 2nd iteration of the for loop, myActivity = "running"
and the method retruns "running" as the activity type , meanwhile we expect the returned activity to be "walking".
In sum, in order to get the activity type (walking/running) with the highest confidence, I modified walkingOrRunning() method to the following
[ fyi: I have implemented and tested the code and it's working as expected, I welcome any feedback/comment/question].
private DetectedActivity walkingOrRunning(List<DetectedActivity> probableActivities) {
DetectedActivity myActivity = null;
int confidence = 0;
for (DetectedActivity activity : probableActivities) {
if (activity.getType() != DetectedActivity.RUNNING && activity.getType() != DetectedActivity.WALKING)
continue;
if (activity.getConfidence() >= confidence) {
confidence = activity.getConfidence();
myActivity = activity;
}
}
return myActivity;
}