Android中判断service是否在运行
/** * 判断服务是否开启 * * @return */ public static boolean isServiceRunning(Context context, String ServiceName) { if (TextUtils.isEmpty(ServiceName)) { return false; } ActivityManager myManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); ArrayList<ActivityManager.RunningServiceInfo> runningService = (ArrayList<ActivityManager.RunningServiceInfo>) myManager.getRunningServices(1000); for (int i = 0; i < runningService.size(); i++) { Log.i("服务运行1:",""+runningService.get(i).service.getClassName().toString()); if (runningService.get(i).service.getClassName().toString().equals(ServiceName)) { return true; } } return false; }