Android: Perceptibility of Applications
The current app that I'm developing requires me to know which apps the user is currently interacting with in any way (and there's no malicious intent here). That is, there are always loads of running app processes and services, but only a select few are actually instantiated or monitored by the user.
I only want to deal with the app processes that are running that the user knows are running. For example, it could be the current app in the foreground, and the music they are playing in the background. However, I want to ignore, say, the SetCPU, Maps, and keyboard services that are always running.
Most of this information can be had through a particular application's RunningAppProcessInfo
instance, and within that the importance
field. For the application in the foreground, the field would be set to IMPORTANCE_FOREGROUND
. For my other condition (the music example one), there is a bit of an issue: there exists a IMPORTANCE_PERCEPTIBLE
constant which would handle this scenario perfectly, but it's only relevant for API 9 and above (Gingerbread, effectively). After perusing the Android source, it appears that this particular value is set at a very low level in the Android OS, and is thus not something that is easily recreatable.
After that huge wall of text, my question is... how do I work around this? I need to be able to distinguish a music开发者_StackOverflow社区 player (just happens to be the only example I can think of) from docile services, but at the same time I can't afford to relegate my app to only those who are running Gingerbread. What's a developer to do?!
I'm not entirely sure if this is possible for non-root users but if you can track which application is held in the foreground. Then you can safely assume that any processes and services that application had are important to the user.
Alot of applications pop up in the background (maps for instance does this sometimes). If the user never opened the app we can assume they don't care about it and we can flag that service as ignored.
You could also weigh the applications. Say as a percentage of user time spent. Then any apps that fall below a certain weight are now ignored.
精彩评论