is Notify Service Running - Android Android OS

Android examples for Android OS:Service

Description

is Notify Service Running

Demo Code


//package com.java2s;
import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.Context;

public class Main {
    public static boolean isNotifyServiceRunning(Context context,
            String serviceName) {
        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningServiceInfo> serviceInfo = activityManager
                .getRunningServices(100);
        for (RunningServiceInfo info : serviceInfo) {
            String name = info.service.getClassName();
            if (name.equals(serviceName)) {
                return true;
            }//from  www. j  av a2 s . co  m
        }
        return false;

    }
}

Related Tutorials