Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * This software and related documentation ("CK-Telecom Software") are
 * protected under relevant copyright laws. The information contained herein
 * is confidential and proprietary to CK-Telecom. and/or its licensors.
 * Without the prior written permission of CK-Telecom. and/or its licensors,
 * any reproduction, modification, use or disclosure of CK-Telecom Software,
 * and information contained herein, in whole or in part, shall be strictly              
 * prohibited.
 * CK-Telecom (C) 2012. All rights reserved.
 */

import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;

import android.content.ComponentName;
import android.content.Context;

import android.util.Log;

public class Main {
    public static boolean isServiceExisted(Context context, String className) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> serviceList = activityManager
                .getRunningServices(Integer.MAX_VALUE);

        if (!(serviceList.size() > 0)) {
            return false;
        }

        for (int i = 0; i < serviceList.size(); i++) {
            RunningServiceInfo serviceInfo = serviceList.get(i);
            ComponentName serviceName = serviceInfo.service;
            Log.d("services", serviceName.getClassName());
            if (serviceName.getClassName().equals(className)) {
                return true;
            }
        }
        return false;
    }
}