Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.app.ActivityManager;

import android.content.Context;

import java.util.List;

public class Main {

    public static boolean isServiceRunning(Context context, String className) {
        if (context == null) {
            return false;
        }

        boolean isRunning = false;
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        ;
        List<ActivityManager.RunningServiceInfo> lists = am.getRunningServices(1000);
        for (ActivityManager.RunningServiceInfo info : lists) {
            if (info.service.getClassName().equals(className)
                    && info.service.getPackageName().equals(context.getPackageName())) {
                isRunning = true;
                break;
            }
        }

        return isRunning;
    }
}