android.app.ActivityManager.RunningServiceInfo Java Examples

The following examples show how to use android.app.ActivityManager.RunningServiceInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java    From android-utils with MIT License 6 votes vote down vote up
/**
 * Checks if the service with the given name is currently running on the device.
 *
 * @param serviceName Fully qualified name of the server. <br/>
 *                    For e.g. nl.changer.myservice.name
 **/
public static boolean isServiceRunning(Context ctx, String serviceName) {

    if (serviceName == null) {
        throw new NullPointerException("Service name cannot be null");
    }

    // use application level context to avoid unnecessary leaks.
    ActivityManager manager = (ActivityManager) ctx.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (service.service.getClassName().equals(serviceName)) {
            return true;
        }
    }

    return false;
}
 
Example #2
Source File: SystemTool.java    From FriendBook with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 判断某个服务是否正在运行的方法
 *
 * @param mContext
 * @param serviceName
 *            是包名+服务的类名(例如:net.loonggg.testbackstage.TestService)
 * @return true代表正在运行,false代表服务没有正在运行
 */
public boolean isServiceWork(Context mContext, String serviceName) {
    boolean isWork = false;
    ActivityManager myAM = (ActivityManager) mContext
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> myList = myAM.getRunningServices(40);
    if (myList.size() <= 0) {
        return false;
    }
    for (int i = 0; i < myList.size(); i++) {
        String mName = myList.get(i).service.getClassName().toString();
        if (mName.equals(serviceName)) {
            isWork = true;
            break;
        }
    }
    return isWork;
}
 
Example #3
Source File: CommonHelper.java    From fanfouapp-opensource with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the recording service is currently running.
 * 
 * @param ctx
 *            the current context
 * @return true if the service is running, false otherwise
 */
public static boolean isServiceRunning(final Context ctx, final Class<?> cls) {
    final ActivityManager activityManager = (ActivityManager) ctx
            .getSystemService(Context.ACTIVITY_SERVICE);
    final List<RunningServiceInfo> services = activityManager
            .getRunningServices(Integer.MAX_VALUE);

    for (final RunningServiceInfo serviceInfo : services) {
        final ComponentName componentName = serviceInfo.service;
        final String serviceName = componentName.getClassName();
        if (serviceName.equals(cls.getName())) {
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: BackgroundServicePluginLogic.java    From cbsp with MIT License 6 votes vote down vote up
private boolean isServiceRunning()
{
	boolean result = false;
	
	try {
		// Return Plugin with ServiceRunning true/ false
		ActivityManager manager = (ActivityManager)this.mContext.getSystemService(Context.ACTIVITY_SERVICE); 
		for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { 
			if (this.mServiceName.equals(service.service.getClassName())) { 
				result = true; 
			} 
		} 
	} catch (Exception ex) {
		Log.d(LOCALTAG, "isServiceRunning failed", ex);
	}

    return result;
}
 
Example #5
Source File: FeaturesUtils.java    From Alibaba-Android-Certification with MIT License 6 votes vote down vote up
/**
 * 判断服务是否启动
 * @param context
 * @param serviceName
 * @return
 */
public static boolean isRunning(Context context,String serviceName)
{
	ActivityManager myAM=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); 
	ArrayList<RunningServiceInfo> runningServices = (ArrayList<RunningServiceInfo>) myAM.getRunningServices(40);
	//获取最多40个当前正在运行的服务,放进ArrList里,以现在手机的处理能力,要是超过40个服务,估计已经卡死,所以不用考虑超过40个该怎么办
	for(int i = 0 ; i<runningServices.size();i++)//循环枚举对比
	{
		String className=runningServices.get(i).service.getClassName();
		if(className.equals(serviceName))
		{
			return true;
		}
	}
	return false;
}
 
Example #6
Source File: LetvTools.java    From letv with Apache License 2.0 6 votes vote down vote up
public static boolean checkServiceIsRunning(Context context, String serviceName) {
    if (context == null || TextUtils.isEmpty(serviceName)) {
        return false;
    }
    ActivityManager manager = (ActivityManager) context.getSystemService("activity");
    if (manager == null) {
        return false;
    }
    List<RunningServiceInfo> list = manager.getRunningServices(Integer.MAX_VALUE);
    if (BaseTypeUtils.isListEmpty(list)) {
        return false;
    }
    for (RunningServiceInfo service : list) {
        if (service != null && service.service != null && serviceName.equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example #7
Source File: TransportBroker.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * We want to check to see if the Router service is already up and running
 *
 * @param context
 * @return
 */
private boolean isRouterServiceRunning(Context context) {
    if (context == null) {

        return false;
    }
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        //We will check to see if it contains this name, should be pretty specific
        if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SdlBroadcastReceiver.SDL_ROUTER_SERVICE_CLASS_NAME)) {
            this.routerClassName = service.service.getClassName();
            this.routerPackage = service.service.getPackageName();
            return true;
        }
    }
    return false;
}
 
Example #8
Source File: RouterServiceValidator.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * This method will find which router service is running. Use that info to find out more about that app and service.
 * It will store the found service for later use and return the package name if found. 
 * @param pm An instance of a package manager. This is no longer used so null can be sent.
 * @return
 */
public ComponentName componentNameForServiceRunning(PackageManager pm){
	if(context==null){
		return null;
	}
	ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
	//PackageManager pm = context.getPackageManager();
	
	
	for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
		//Log.d(TAG, service.service.getClassName());
		//We will check to see if it contains this name, should be pretty specific
		if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SdlBroadcastReceiver.SDL_ROUTER_SERVICE_CLASS_NAME)){ 
			//this.service = service.service; //This is great
			if(service.started && service.restarting==0){ //If this service has been started and is not crashed
				return service.service; //appPackageForComponenetName(service.service,pm);
			}
		}
	}			

	return null;
}
 
Example #9
Source File: DownloadService.java    From AndroidDownloader with Apache License 2.0 6 votes vote down vote up
private static boolean isServiceRunning(Context context) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> serviceList = activityManager
            .getRunningServices(Integer.MAX_VALUE);

    if (serviceList == null || serviceList.size() == 0) {
        return false;
    }

    for (int i = 0; i < serviceList.size(); i++) {
        if (serviceList.get(i).service.getClassName().equals(
                DownloadService.class.getName())) {
            isRunning = true;
            break;
        }
    }
    return isRunning;
}
 
Example #10
Source File: Root.java    From rootinspector with GNU General Public License v2.0 6 votes vote down vote up
public boolean checkRootMethod10() {
	Log.d(Main.TAG, "check11");
	boolean returnValue = false;
	// Get currently running application processes
	List<RunningServiceInfo> list = manager.getRunningServices(300);
	if(list != null){
		String tempName;
		for(int i=0;i<list.size();++i){
			tempName = list.get(i).process;
			Log.d(Main.TAG, "process: " + tempName);
			if(tempName.contains("supersu") || tempName.contains("superuser")){
				Log.d(Main.TAG, "found one!");
				returnValue = true;
			}
		}
	}
	return returnValue;
}
 
Example #11
Source File: TorchSwitch.java    From Torch with GNU General Public License v3.0 6 votes vote down vote up
private boolean isTorchServiceRunning(Context context) {

        ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> mList = mActivityManager.getRunningServices(100);

        if (!(mList.size() > 0)) {
            return false;
		}
        for (RunningServiceInfo mServiceInfo : mList) {
            ComponentName mServiceName = mServiceInfo.service;
            if (mServiceName.getClassName().endsWith(".TorchService")
                    || mServiceName.getClassName().endsWith(".RootTorchService"))
                return true;
        }
        return false;
    }
 
Example #12
Source File: PackageManagerUtil.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
/**
     * 停止本应用内的所有Service
     * @param context context
     */
    public static void stopAllServiceOfApp(final Context context) {
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        if (manager == null) {
            return;
        }
        for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (context.getPackageName().equals(service.service.getPackageName())) {
                Intent stopIntent = new Intent();
                ComponentName serviceCMP = service.service;
                stopIntent.setComponent(serviceCMP);
                context.stopService(stopIntent);
                // new AppRecManager(context).unregisterListener();
                break;
            }
        }
//        android.os.Process.killProcess(android.os.Process.myPid());
//        System.exit(0);
    }
 
Example #13
Source File: Application.java    From batteryhub with Apache License 2.0 6 votes vote down vote up
/**
 * Helper to query whether an application is currently running
 * and its code has not been evicted from memory.
 *
 * @param context Application's context
 * @param appName The package name or process name of the application.
 * @return true if the application is running, false otherwise.
 */
public static boolean isRunning(final Context context, String appName) {
    List<RunningAppProcessInfo> runningProcessInfo = Process.getRunningProcessInfo(context);
    List<RunningServiceInfo> services = Service.getRunningServiceInfo(context);

    for (RunningAppProcessInfo info : runningProcessInfo) {
        if (info.processName.equals(appName) &&
                info.importance != RunningAppProcessInfo.IMPORTANCE_EMPTY) {
            return true;
        }
    }

    for (RunningServiceInfo service : services) {
        String name = StringHelper.formatProcessName(service.process);
        if (name.equals(appName)) return true;
    }

    return false;
}
 
Example #14
Source File: MainActivity.java    From deskcon-android with GNU General Public License v3.0 5 votes vote down vote up
private boolean isControlServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (ControlService.class.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example #15
Source File: ApkInstrumenterActivity.java    From hk with GNU General Public License v3.0 5 votes vote down vote up
private boolean checkIfServiceIsRunning() {
	// If the service is running when the activity starts, we want to
	// automatically bind to it.
	ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
	for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
		if (InstrumentationService.class.getName().equals(service.service.getClassName())) {
			serviceStarted.setText("OFF");
			return true;
		}
	}
	return false;
}
 
Example #16
Source File: ServiceStatusUtils.java    From weixin with Apache License 2.0 5 votes vote down vote up
/**
 * 判断一个服务是否处于开启状态
 * @param context 上下文
 * @param serviceClassname 服务的完整的类名称
 * @return
 */
public static boolean  isServiceRunning(Context context,String serviceClassname){
	ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
	List<RunningServiceInfo>  serviceInfos = am.getRunningServices(100);
	for(RunningServiceInfo serviceInfo : serviceInfos){
		String servicename = serviceInfo.service.getClassName();
		if(serviceClassname.equals(servicename)){
			return true;
		}
	}
	return false;
}
 
Example #17
Source File: RouterServiceValidator.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This method will determine if our supplied component name is really running. 
 * @param context
 * @param service
 * @return
 */
protected boolean isServiceRunning(Context context, ComponentName service){
	 ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
	    for (RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) {
	        if (serviceInfo.service.equals(service)) {
	            return true;
	        }
	    }
	return false;
}
 
Example #18
Source File: AndroidComponentUtil.java    From ribot-app-android with Apache License 2.0 5 votes vote down vote up
public static boolean isServiceRunning(Context context, Class serviceClass) {
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example #19
Source File: DfuFragment.java    From Android-nRF-Beacon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean isDfuServiceRunning() {
	ActivityManager manager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
	for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
		if (DfuService.class.getName().equals(service.service.getClassName())) {
			return true;
		}
	}
	return false;
}
 
Example #20
Source File: PackageUtils.java    From Android-Next with Apache License 2.0 5 votes vote down vote up
public static boolean isServiceRunning(Context context, Class<?> cls) {
    final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final List<RunningServiceInfo> services = am.getRunningServices(Integer.MAX_VALUE);
    final String className = cls.getName();
    for (RunningServiceInfo service : services) {
        if (className.equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example #21
Source File: MainActivity.java    From PacketSender-Android with MIT License 5 votes vote down vote up
public RunningServiceInfo getServiceIntent() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("com.packetsender.android.PacketListenerService".equals(service.service.getClassName())) {
            return service;
        }
    }

    return null;
}
 
Example #22
Source File: MainActivity.java    From PacketSender-Android with MIT License 5 votes vote down vote up
public static boolean isMyServiceRunning(Context ctx) {
    ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("com.packetsender.android.PacketListenerService".equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example #23
Source File: MizLib.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
public static boolean isMovieLibraryBeingUpdated(Context c) {
    ActivityManager manager = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> services = manager.getRunningServices(Integer.MAX_VALUE);
    int count = services.size();
    for (int i = 0; i < count; i++) {
        if (MovieLibraryUpdate.class.getName().equals(services.get(i).service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example #24
Source File: DfuActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean isDfuServiceRunning() {
	final ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
	for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
		if (DfuService.class.getName().equals(service.service.getClassName())) {
			return true;
		}
	}
	return false;
}
 
Example #25
Source File: AbAppUtil.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static boolean isServiceRunning(Context context, String className) {
    boolean isRunning = false;
    for (RunningServiceInfo si : ((ActivityManager) context.getSystemService("activity")).getRunningServices(Integer.MAX_VALUE)) {
        if (className.equals(si.service.getClassName())) {
            isRunning = true;
        }
    }
    return isRunning;
}
 
Example #26
Source File: DexcomG4Activity.java    From MedtronicUploader with GNU General Public License v2.0 5 votes vote down vote up
private boolean isMyServiceRunning() {
   
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
    	if (isServiceAlive(service.service.getClassName()))
    		return true;
    }
    return false;
}
 
Example #27
Source File: Utils.java    From Noyze with Apache License 2.0 5 votes vote down vote up
public static boolean isMyServiceRunning(Context context, String serviceClass) {
    if (null == serviceClass || null == context) return false;
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> services = manager.getRunningServices(Integer.MAX_VALUE);
    for (RunningServiceInfo service : services) {
        if (serviceClass.equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example #28
Source File: ServiceUtil.java    From BalloonPerformer with Apache License 2.0 5 votes vote down vote up
/**
 * 服务是否运行中
 * 
 * @param context
 * @param serviceName
 * @return
 */
public static boolean isWorked(Context context, String serviceName) {
    ActivityManager myManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    ArrayList<RunningServiceInfo> runningService = (ArrayList<RunningServiceInfo>) myManager
            .getRunningServices(Integer.MAX_VALUE);
    for (RunningServiceInfo runningServiceInfo : runningService) {
        if (runningServiceInfo.service.getClassName().equals(serviceName)) {
            return true;
        }
    }
    return false;
}
 
Example #29
Source File: MizLib.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
public static boolean isTvShowLibraryBeingUpdated(Context c) {
    ActivityManager manager = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> services = manager.getRunningServices(Integer.MAX_VALUE);
    int count = services.size();
    for (int i = 0; i < count; i++) {
        if (TvShowsLibraryUpdate.class.getName().equals(services.get(i).service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
Example #30
Source File: ServiceTools.java    From external-nfc-api with Apache License 2.0 5 votes vote down vote up
public static boolean isServiceRunning(String serviceClassName, Context context) {
    final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final List<RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);

    for (RunningServiceInfo runningServiceInfo : services) {
        if (runningServiceInfo.service.getClassName().equals(serviceClassName)) {
            return true;
        }
    }
    return false;
}