Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import android.content.Context;

import android.text.TextUtils;
import java.util.List;

public class Main {

    public static boolean isServiceRunning(Context context, String serviceName) {
        if (TextUtils.isEmpty(serviceName)) {
            return false;
        }
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> mServiceList = manager.getRunningServices(100);
        for (int i = 0; i < mServiceList.size(); i++) {
            String clasString = mServiceList.get(i).service.getClassName();
            if (clasString.equals(serviceName)) {
                return true;
            }
        }
        return false;
    }
}