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; }
/** * 判断某个服务是否正在运行的方法 * * @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; }
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; }
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; }
/** * 获取服务是否开启 * @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; }
@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)); } } }
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; }
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; }
@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); } }
/** * @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; }
/** * 退出应用 * @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); }
/** * 判断某个服务是否正在运行的方法 * @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; }
/** * 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; }
/** * 用来判断服务是否运行. * * @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; }
/** * * @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; }
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; }
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; }
/** * 校验服务是否处于运行中 * @param context * @param serviceName * @return */ public static boolean isServiceRunning(Context context, String serviceName) { ActivityManager am = (ActivityManager)context.getSystemService(context.ACTIVITY_SERVICE); List<RunningServiceInfo> infos = am.getRunningServices(100); Log.i("ServiceUtils", "checking: " + serviceName); for (RunningServiceInfo info : infos) { //得到正在运行的服务名 String name = info.service.getClassName(); if (serviceName.equals(name)) { Log.i("ServiceUtils", "result:isRunning"); return true; } } return false; }
/** * 检查某个服务还在运行 * @param context * @param serviceName 服务的名称。 * @return */ public static boolean isServiceRunning(Context context,String serviceName){ //不仅可以管理Activity还可管理Service. ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); //返回正在运行的服务List.maxNum为返回的最大服务数。 int maxNum = 100; List<RunningServiceInfo> services = activityManager.getRunningServices(maxNum ); //循环取出服务的className与传入的服务名称(含包名和类名)比较,如果有相同的,说明此服务还在运行。 for(RunningServiceInfo info : services) { String name = info.service.getClassName(); if(name.equals(serviceName)){ return true; } } return false; }
/** * 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 context * @return */ public ComponentName componentNameForServiceRunning(PackageManager pm){ if(context==null){ return null; } ActivityManager manager = (ActivityManager) context.getSystemService("activity"); //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; }
/** * 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; }
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; }
/** * 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; }
public boolean myGlassRunning(){ TextView tv = (TextView) findViewById(R.id.textView2); tv.setText(""); ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); // am.killBackgroundProcesses("com.google.glass.companion"); List<RunningServiceInfo> pids = am.getRunningServices(9999); for (int i = 0; i < pids.size(); i++) { ActivityManager.RunningServiceInfo info = pids.get(i); //Log.d("JOE",info.service.getClassName()); if (info.service.getClassName().equals("com.google.glass.companion.service.CompanionService")){ Log.d("JOE","MyGlass is running"); myglassrunning = true; tv = (TextView) findViewById(R.id.textView2); tv.setText("MyGlass is running. It blocks the Bluetooth channel needed to talk to glass. In order to use this app please Force Stop or uninstall it."); return true; } } return false; }
/** * Is the service running. * @param ctx Application context. * @return Is the cover closed. */ public static boolean service_running(Context ctx, Class svc) { Log.d("F.Is.service_running", "Is service running called."); ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (svc.getName().equals(service.service.getClassName())) { // the service is running Log.d("F.Is.service_running", "The " + svc.getName() + " is running."); return true; } } // the service must not be running Log.d("F.Is.service_running", "The " + svc.getName() + " service is NOT running."); return false; }
/** * 获取所有运行的服务 * * @return 服务名集合 */ public static Set getAllRunningService() { ActivityManager activityManager = (ActivityManager) Utils.getApp().getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> info = activityManager.getRunningServices(0x7FFFFFFF); Set<String> names = new HashSet<>(); if (info == null || info.size() == 0) return null; for (RunningServiceInfo aInfo : info) { names.add(aInfo.service.getClassName()); } return names; }
/** * 判断服务是否运行 * * @param className 完整包名的服务类名 * @return {@code true}: 是<br>{@code false}: 否 */ public static boolean isServiceRunning(final String className) { ActivityManager activityManager = (ActivityManager) Utils.getApp().getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> info = activityManager.getRunningServices(0x7FFFFFFF); if (info == null || info.size() == 0) return false; for (RunningServiceInfo aInfo : info) { if (className.equals(aInfo.service.getClassName())) return true; } return false; }
/** * 获取所有运行的服务 * * @return 服务名集合 */ public static Set getAllRunningService() { ActivityManager activityManager = (ActivityManager) Utils.getContext().getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> info = activityManager.getRunningServices(0x7FFFFFFF); Set<String> names = new HashSet<>(); if (info == null || info.size() == 0) return null; for (RunningServiceInfo aInfo : info) { names.add(aInfo.service.getClassName()); } return names; }
/** * 判断服务是否运行 * * @param className 完整包名的服务类名 * @return {@code true}: 是<br>{@code false}: 否 */ public static boolean isServiceRunning(String className) { ActivityManager activityManager = (ActivityManager) Utils.getContext().getSystemService(Context.ACTIVITY_SERVICE); List<RunningServiceInfo> info = activityManager.getRunningServices(0x7FFFFFFF); if (info == null || info.size() == 0) return false; for (RunningServiceInfo aInfo : info) { if (className.equals(aInfo.service.getClassName())) return true; } return false; }
/** * 检测服务是否运行 * * @param context 上下文 * @param className 类名 * @return 是否运行的状态 */ 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); for (RunningServiceInfo si : servicesList) { if (className.equals(si.service.getClassName())) { isRunning = true; } } return isRunning; }
public static boolean isServiceRunning(Context context, Class<?> serviceClass) { for (RunningServiceInfo service : ((ActivityManager) context.getSystemService("activity")).getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { return true; } } return false; }
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; }
public static boolean checkServiceIsRunning(Context context) { for (RunningServiceInfo service : ((ActivityManager) context.getSystemService("activity")).getRunningServices(Integer.MAX_VALUE)) { if ("com.letv.android.client.worldcup.LetvDownloadService".equals(service.service.getClassName())) { Constants.debug("com.letv.android.client.worldcup.LetvDownloadService is Running"); return true; } } return false; }
public static boolean isServiceRunning(Context mContext, String className) { boolean isRunning = false; List<RunningServiceInfo> serviceList = ((ActivityManager) mContext.getSystemService("activity")).getRunningServices(Integer.MAX_VALUE); if (serviceList.size() <= 0) { return false; } for (int i = 0; i < serviceList.size(); i++) { if (((RunningServiceInfo) serviceList.get(i)).service.getClassName().equals(className)) { LogInfo.log("XX", "isServiceRunning name " + ((RunningServiceInfo) serviceList.get(i)).service.getClassName()); isRunning = true; break; } } return isRunning; }
public static ComponentName isServiceExisted(Context context, String packageName) { for (RunningServiceInfo runningServiceInfo : ((ActivityManager) context.getSystemService("activity")).getRunningServices(Integer.MAX_VALUE)) { ComponentName serviceName = runningServiceInfo.service; if (serviceName.getPackageName().equals(packageName) && serviceName.getClassName().equals(new StringBuilder(String.valueOf(packageName)).append(".business.RemoteSSOService").toString())) { return serviceName; } } return null; }
/** * 检测服务是否运行 * * @param context 上下文 * @param className 类名 * @return 是否运行的状态 */ 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); for (RunningServiceInfo si : servicesList) { if (className.equals(si.service.getClassName())) { isRunning = true; } } return isRunning; }