Is there any way to get current running foreground application (package) for all available OS?

时光怂恿深爱的人放手 提交于 2020-11-28 01:46:13

问题


I know, too many questions already raised on this topic but, that are not supported in all OS / devices

Question

  1. Is there any way to get current running foreground application (package) for all available OS?
  2. How AppLock works (how it detects any app launches)?

What I have tried (but failed)

  1. How do I detect if an android app is launched? - Google has disabled in Android L.
  2. How to use UsageStatsManager? - android.permission.GET_TASKS is depricated.
  3. How to make my app a device owner? - Cannot execute this command pro-grammatically.
  4. ?
  5. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!