Android check if a particular service is running


public static boolean isAppRunning(final Context context, 
              final String packageName) {

  final ActivityManager activityManager = 
       (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

  final List<ActivityManager.RunningAppProcessInfo> procInfos = 
       activityManager.getRunningAppProcesses();

  if (procInfos != null)
  {
    for (final ActivityManager.RunningAppProcessInfo processInfo : procInfos) {
      if (processInfo.processName.equals(packageName)) {
        return true;
      }
    }
  }
  return false;
}

In my case packageName was` ​com.example.myService:qt`

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s