问题
I know, too many questions already raised on this topic but, that are not supported in all OS / devices
Question
- Is there any way to get current running foreground application (package) for all available OS?
- How AppLock works (how it detects any app launches)?
What I have tried (but failed)
- How do I detect if an android app is launched? - Google has disabled in Android L.
- How to use UsageStatsManager? -
android.permission.GET_TASKS
is depricated. - How to make my app a device owner? - Cannot execute this command pro-grammatically.
- ?
- Knox Standard SDK
What I want
- User should not able to access black listed app. My app should launch in front of black listed app (as same as AppLock does)
- User can only access apps, that are white listed.
- I have tried many more solution, but not able to get perfect solution that can work in all available OS / devices.
- I want solution programmatically / free / for each device and OS
回答1:
You can have 2 approaches to this that may be acceptable, otherwise you are probably out of luck.
1) Make your app the "launcher" app. Users will then be interacting with your app in order to launch apps in general. Notification based launches and other types of interactions you may not be able to track, but I have not tried.
2) Make your app "pretend" to be a launcher app. After it launches, it displays a launcher type screen. You then have to handle attempts to press "home" by checking if your app is in the background and bringing it into foreground if it is. This is not an easy task - it's likely you will have bugs, etc. but it seems possible (I only know that determining if your app is "in the background" can be tricky because dialog boxes and notifications can take the foreground, but you do not want to dismiss those (most of the time I assume).
Good luck!
来源:https://stackoverflow.com/questions/48058759/is-there-any-way-to-get-current-running-foreground-application-package-for-all