2

I have seen many solutions to check if our own app is minimized,running or background.but is there a way to check if another app package is running or minimized so that based on that we can run a code.like an app-locker.Here we need to turn off network for a certain apps according to the user selection on installed apps in device, so when that selected apps are on foreground, network should be disabled when the selected apps are closed or minimized.then enable the network. Will it be compliant with Google play if we make such an app? because somewhere i read they don't allow apps that interfere with other apps.so confused.

unitedartinc
  • 738
  • 1
  • 6
  • 25

1 Answers1

1

TL;DR: Google doesn't want you to do this, and you shouldn't try.

The old hack that relied on ActivityManager#getRecentTasks() to find out which app is in the foreground was disabled starting in Android 5.0.

App lockers that work on Lollipop are using a new hack involving ActivityManager#getRunningAppProcesses(). How it works is described in this answer. This hack is reportedly broken on Android M.

There's a new UsageStats API from which you might be able to glean a bit of info, but it requires a permission that can only be granted by a system activity. It's documented that this system activity may not be present on all devices. Samsung and LG are among the manufacturers that have reportedly removed this activity from their Lollipop devices, so only system apps will ever be able to use UsageStats.

The bottom line is that Google has shown their commitment to preventing what you're trying to do. Even if you find a temporary solution, you can bet that it will stop working in a future Android version. Eventually, Google will close all the loopholes and your app will be permanently broken. So it's probably a waste of time to write a new app that depends on this capability.

Community
  • 1
  • 1
Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82
  • i mean, if applocker is doing same and its still available on google play right? then why we cant make this app? – unitedartinc Jul 02 '15 at 14:15
  • yes i did, but still confused whether google play will remove that app or not, (applocker app is still used by many people right?) so google will remove our app, keeping big apps still there? sorry for my bad english may be i didnt understand what you written. – unitedartinc Jul 02 '15 at 18:02
  • @unitedartinc It's not that Google will remove it from the play store. The current version of app locker will simply stop working on future versions of Android. The previous version stopped working on Lollipop, and we already know that the current version will not work on M. If they find another hack to keep it working on M, Google will probably break it in N. It's a huge waste of time to try to fight Google on things like this, and eventually they'll close all the loopholes and it'll be game over for your app. Best not to even try. – Kevin Krumwiede Jul 02 '15 at 18:30