I'm developing an app profiling user behavior for security reasons. I wrote a service with this snippet, that detects all services in foreground in a device running Android OS 4.4
and collects them in a list.
List<ActivityManager.RunningServiceInfo> l = activityManager.getRunningServices(50);
Iterator<ActivityManager.RunningServiceInfo> i = l.iterator();
while (i.hasNext()) {
ActivityManager.RunningServiceInfo runningServiceInfo = (ActivityManager.RunningServiceInfo) i.next();
if (runningServiceInfo.foreground) {
newList.add(runningServiceInfo.service.getClassName());
}
}
I tried this once on a device with Android OS 5.0
and I noticed that it doesn't detect services in foreground, like runtastic's service foreground
and other apps built for this SDK version and above.
Could it depend on new foreground services policy?