In my Android application, I want to display a notification only when the user is not moving or only slowly moving. For example, when a user is driving, I don't want to display notifications. To accomplish this, I've looked into the Activity Recognition API and implemented a basic component -- and it basically works alright.
During some first test, I've noticed that occasionally see some strange output when I simply check for the activity with the highest confidence, e.g., getting a IN_VEHICLE
while walking. Since this is based on statistics and what not, I'm not surprised of that. I, therefore, use simple sliding window over the last N activity types. Only when all values in the window are the same, I assume the respective activity.
Now I have 3 configuration parameters:
TIME_BETWEEN_REQUESTS
(in milliseconds) as the minimum time between the request for the current activity value as part of the Activity Recognition API. The lower to value the more up-to-date but the higher the battery drain. For testing, I currently set it only to 5000 (=5sec)MIN_CONFIDENCE
(0..100) minimum confidence referringDetectedActivity.getConfidence()
. Only if the confidence is larger than this threshold, I consider that the API is confident enough about the detected activity. On the Web, I see most commonly aMIN_CONFIDENCE >= 75
WINDOW_SIZE
(>= 1) as the minimum number of the same activity types before I'm sure about the detected activity. Currently, I useWINDOW_SIZE = 3
. So if a user is walking and the phone detects an occasionalIN_VEHICLE
I don't immediately assume that the users are driving. Only if the next two values are alsoIN_VEHICLE
, I change the user's activity state.
Does this make sense? I'm a bit worried if I increase TIME_BETWEEN_REQUESTS
-- What is a practical value anyway -- because it takes at least WINDOW_SIZE * TIME_BETWEEN_REQUEST
before the activity state of a user will change. Right now it's 15sec, but if I would set TIME_BETWEEN_REQUESTS
to 30sec and keep WINDOW_SIZE 3
, it would require at least 90sec for a change to occur.
What are good/best practices here? Is the window even necessary or do larger values for TIME_BETWEEN_REQUESTS
already do some kind of smoothing?