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;

public class Main {
    public static final boolean checkServiceRunning(final Context context, final String serviceName) {
        final ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (final RunningServiceInfo info : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (info.service.getClassName().equals(serviceName) && info.pid > 0) {
                return true;
            }
        }
        return false;
    }
}