Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.app.ActivityManager;

import android.app.ActivityManager.RunningServiceInfo;

import android.content.Context;

import java.util.List;

public class Main {
    public static boolean isServiceRunning(Context context, String serviceName) {
        ActivityManager manger = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningServiceInfo> rs = manger.getRunningServices(50);

        for (RunningServiceInfo rsi : rs) {
            String className = rsi.service.getClassName();
            if (className.equals(serviceName)) {
                return true;
            }
        }
        return false;
    }
}