Reputation: 2605
Is it possible for a service to check the following
Upvotes: 2
Views: 602
Reputation: 4199
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.
Upvotes: 0
Reputation: 34775
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
Upvotes: 2