Is it possible for a service to check the following
- Whether a App is running or not?
- If yes, is it App running is background or foreground? Please suggest some way to do it.
Is it possible for a service to check the following
You need to use getRunningTasks to know whether the app is running or not.
From the docs:
public List getRunningTasks (int maxNum)
Return a list of the tasks that are currently running, with the most recent being first and older ones after in order.
For this to work you should include this in your AndroidManifest.xml
<uses-permission android:name="android.permission.GET_TASKS" />
And regarding App running background/foreground refer this LINK
List<RunningAppProcessInfo> apps = ((ActivityManager) _context.getSystemService(Context.ACTIVITY_SERVICE)).getRunningAppProcesses();
...that's the way u get every running app, just use "apps.get(i).processName" or sth to get the processname u can check for.
And use <uses-permission android:name="android.permission.GET_TASKS" />
in your manifest, to make sure u have the right permission.