当前位置: 首页>>代码示例>>Java>>正文


Java RunningServiceInfo类代码示例

本文整理汇总了Java中android.app.ActivityManager.RunningServiceInfo的典型用法代码示例。如果您正苦于以下问题:Java RunningServiceInfo类的具体用法?Java RunningServiceInfo怎么用?Java RunningServiceInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RunningServiceInfo类属于android.app.ActivityManager包,在下文中一共展示了RunningServiceInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
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;
}
 
开发者ID:lifengsofts,项目名称:AndroidDownloader,代码行数:21,代码来源:DownloadService.java

示例2: isServiceWork

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
/**
 * 判断某个服务是否正在运行的方法
 *
 * @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;
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:26,代码来源:SystemTool.java

示例3: IsServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
public boolean IsServiceRunning(@NonNull Class<?> serviceClass) {
    ActivityManager activityManager = (ActivityManager) _context.getSystemService(Context.ACTIVITY_SERVICE);

    if (activityManager == null) {
        Logger.getInstance().Error(TAG, "ActivityManager is null!");
        return false;
    }

    for (RunningServiceInfo service : activityManager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }

    return false;
}
 
开发者ID:GuepardoApps,项目名称:LucaHome-AndroidApplication,代码行数:17,代码来源:AndroidSystemController.java

示例4: checkServiceIsRunning

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
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;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:20,代码来源:LetvTools.java

示例5: isRunningService

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
/**
 * 获取服务是否开启
 * @param className 完整包名的服务类名
 */
public static boolean isRunningService(String className, Context context) {
    // 进程的管理者,活动的管理者
    ActivityManager activityManager = (ActivityManager)
            context.getSystemService(Context.ACTIVITY_SERVICE);
    // 获取正在运行的服务,最多获取1000个
    List<RunningServiceInfo> runningServices = activityManager.getRunningServices(1000);
    // 遍历集合
    for (RunningServiceInfo runningServiceInfo : runningServices) {
        ComponentName service = runningServiceInfo.service;
        if (className.equals(service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:zhuangzaiku,项目名称:AndroidCollection,代码行数:20,代码来源:UnclassifiedUtils.java

示例6: onReceive

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent arg1) {
   

	 ActivityManager manager = (ActivityManager)context.   getSystemService(Context.ACTIVITY_SERVICE);
	 for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
{

    if (digiPune.class.getName().equals(service.service.getClassName())) {
                        //running 
       }
   else{
  	 context.startService(new Intent(context, digiPune.class));
       }

}
}
 
开发者ID:SkylineLabs,项目名称:FindX,代码行数:18,代码来源:BootCompletedReceiver.java

示例7: isServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
private boolean isServiceRunning()
{
	boolean running = false;

	ActivityManager manager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);

	for(RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
	{
		if(SensorService.class.getName().equals(service.service.getClassName()))
		{
			running = true;
			break;
		}
	}

	return running;
}
 
开发者ID:piatt,项目名称:GestureWave,代码行数:18,代码来源:SettingsActivity.java

示例8: isServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
public static boolean isServiceRunning(Context mContext,String className) {

		boolean isRunning = false;

		ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
		List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(30);

		if (!(serviceList.size()>0)) {
			return false;
		}
		for (int i=0; i<serviceList.size(); i++) {
			if (serviceList.get(i).service.getClassName().equals(className) == true) {
				isRunning = true;
				break;
			}
		}
		return isRunning;
	}
 
开发者ID:Tencent,项目名称:WeTest-Assistant,代码行数:19,代码来源:ApkManager.java

示例9: getData

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
@Override
    protected void getData() {

        List<RunningServiceInfo> liServices = m_activityManager.getRunningServices(MAXIMUM_SERVICES);
        List<RunningAppProcessInfo> runningAppProcesses = m_activityManager.getRunningAppProcesses();
        // liTasks.get(0).

        // Account[] accounts = m_activityManager.getAccounts();
        // String[] strAccountTypes = new String[accounts.length];
        //
        // for (int i = 0; i < accounts.length; i++) {
        // strAccountTypes[i] = accounts[i].type;
        // }

        if (!liServices.isEmpty()) {
            // TODO: implement logic
            StringBuilder sb = new StringBuilder();
            // for (int i = 0; i < liProcesses.size() - 1; i++)
            // sb.append(liProcesses.get.type + ";");
            // sb.append(liProcesses[liProcesses.length - 1]);

//			SensorRunningServices sensor = new SensorRunningServices();
//			// sensor.setAccountTypes(sb.toString());
//			handleDBEntry(sensor);
        }
    }
 
开发者ID:Telecooperation,项目名称:assistance-platform-client-sdk-android,代码行数:27,代码来源:RunningAppsReaderSensor.java

示例10: isServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
/**
 * @param context
 *            上下文对象
 * @param ServiceName
 *            要判断的服务的名称
 * @return 返回服务是否开启状态
 */
public static boolean isServiceRunning(Context context, String ServiceName) {

	// 拿到ActivityManager
	ActivityManager activityManager = (ActivityManager) context
			.getSystemService(Context.ACTIVITY_SERVICE);
	// 拿到所有运行的服务
	// 参数:要获取的最大条数
	List<RunningServiceInfo> runningServices = activityManager
			.getRunningServices(200);
	for (RunningServiceInfo runningServiceInfo : runningServices) {
		// System.out.println(runningServiceInfo.service.getClassName());
		// 拿到服务的名称
		String name = runningServiceInfo.service.getClassName();
		if (ServiceName.equals(name)) {
			return true;
		}
	}
	return false;
}
 
开发者ID:paifeng,项目名称:Mobile-guards,代码行数:27,代码来源:ServiceStatusUtils.java

示例11: exitApp

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
/**
 * 退出应用
 * @param context
 */
public static void exitApp(final Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    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);
}
 
开发者ID:feer921,项目名称:BaseProject,代码行数:20,代码来源:PackageManagerUtil.java

示例12: isServiceWork

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
/** 
 * 判断某个服务是否正在运行的方法 
 * @param mContext 
 * @param serviceName 包名+服务的类名(例如:net.yunim.service.EBClientService)
 * @param mark 标记,仅用于打印日志
 * @return true代表正在运行,false代表服务没有正在运行 
 */
public static boolean isServiceWork(Context mContext, String serviceName, String mark) {
    boolean isWork = false;
    ActivityManager myAM = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> myList = myAM.getRunningServices(Integer.MAX_VALUE);
    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)) {
        	Log4jLog.d(LONG_TAG, "service '" + serviceName +"' is found, mark = " + mark);
            isWork = true;
            break;
        }
    }
    
    if (!isWork)
    	Log4jLog.e(LONG_TAG, "service '" + serviceName +"' is not exist, mark = " + mark);
    return isWork;  
}
 
开发者ID:entboost,项目名称:EntboostIM,代码行数:29,代码来源:OtherUtils.java

示例13: isRunning

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
/**
 * Helper to query whether an application is currently running and its code has not been evicted from memory.
 *
 * @param context the 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;
}
 
开发者ID:greenhub-project,项目名称:batteryhub,代码行数:26,代码来源:Application.java

示例14: isServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
/**
 * 用来判断服务是否运行.
 *
 * @param context   the context
 * @param className 判断的服务名字 "com.xxx.xx..XXXService"
 * @return true 在运行 false 不在运行
 */
public static boolean isServiceRunning(Context context, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> servicesList = activityManager
            .getRunningServices(Integer.MAX_VALUE);
    Iterator<RunningServiceInfo> l = servicesList.iterator();
    while (l.hasNext()) {
        RunningServiceInfo si = (RunningServiceInfo) l.next();
        if (className.equals(si.service.getClassName())) {
            isRunning = true;
        }
    }
    return isRunning;
}
 
开发者ID:KouChengjian,项目名称:PhoneMate,代码行数:23,代码来源:AppUtil.java

示例15: isAlive

import android.app.ActivityManager.RunningServiceInfo; //导入依赖的package包/类
/**
 * 
 * @param context
 * @return whether EspPushService is alive background
 */
public static boolean isAlive(Context context)
{
    ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> list = am.getRunningServices(Integer.MAX_VALUE);
    boolean isServiceRunning = false;
    String clsName = EspPushService.class.getName();
    for (RunningServiceInfo info : list) {
        String serviceCls = info.service.getClassName();
        if (serviceCls.equalsIgnoreCase(clsName)) {
            isServiceRunning = true;
            break;
        }
    }
    return isServiceRunning;
}
 
开发者ID:EspressifApp,项目名称:IOT-Espressif-Android,代码行数:21,代码来源:EspPushService.java


注:本文中的android.app.ActivityManager.RunningServiceInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。