Example usage for android.app ActivityManager.RunningServiceInfo getClass

List of usage examples for android.app ActivityManager.RunningServiceInfo getClass

Introduction

In this page you can find the example usage for android.app ActivityManager.RunningServiceInfo getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

/**
 * check whether specific service is running.
 * @param context//  w  w w  .j a  v  a2s  .  c o  m
 * @param serviceClassFullName the full class name of service
 * @return true if service is running
 */
public static boolean isServiceRunning(Context context, String serviceClassFullName) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> runningServices = manager.getRunningServices(1024);
    for (ActivityManager.RunningServiceInfo info : runningServices) {
        if (info.getClass().getName().equals(serviceClassFullName))
            return true;
    }
    return false;
}