Check Service by service class - Android android.app

Android examples for android.app:ActivityManager

Description

Check Service by service class

Demo Code


//package com.java2s;
import android.app.ActivityManager;
import android.content.Context;

public class Main {
    public static boolean fnCheckService(Context context, Class ServiceClass) {
        ActivityManager manager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager
                .getRunningServices(Integer.MAX_VALUE)) {
            if (ServiceClass.getName().equals(
                    service.service.getClassName())) {
                return true;
            }//from ww  w.  java  2 s.  c om
        }
        return false;
    }
}

Related Tutorials