I am making a battery app to monitor user's charging behavior. Basically, it is a background log server that saves your charge profile and analyzes it. Since it is possible that users is using their phones (e.g., playing games) during the charge , this changes the charge behavior. Thus it is necessary for my app to differentiate those data from the others.
Detecting if people is using the phone by a foreground app is trivial (you just check if user is touching your UI). However, I found it is relatively challenging for a background service to do the same thing. The only way comes to my mind is to check the brightness of screen. However, it is also possible that people leave the phone with screen on.
Could anyone give me some suggestions on this problem?
--------- Hi, here is a update of my question --------
First of all, the trick to get foreground app does not work after Android 5.0 (it is also posted getRunningTasks doesn't work in Android L). After Android 5.0, the "getRunningAppProcesses()" only returns your app. Based on the other discussion in Stackoverflow, There is an alternative to use app statistic but which needs system permission. Moreover, it also doesn't work at certain phones (in my test, most Samsung phone is unable to find the option to enable this function).
Second, I test the foreground app trick in some of my phones (before 5.0), but I think it doesn't meet the purpose of knowing if users are "interacting" the phone. For example, it is possible that users are running an app and just walking away for more than few hours but the foreground app trick still thinks the phone is in using (but it is not).