I found a workaround to understand if a user open an app. Just the open process, not bring to foreground a background app.
public int getTotalRunningApp(){
ActivityManager actvityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
return procInfos.size();
}
@Override
public void onTouchEvent(MotionEvent event) {
int runApp = getTotalRunningApp();
Log.wtf(Constants.TAG_APP, "RunningApp = " + runApp);
...
super.onTouchEvent(event);
runApp = getTotalRunningApp();
Log.wtf(Constants.TAG_APP, "RunningApp = " + runApp);
...
}
By calling getTotalRunningApp()
before and after the real super.onTouchEvent
we can monitorize the number of running app and understand "a little" if a user is tapping an app or just moving homescreen or doing nothing.
It's not working with background app.