/** * 判斷服務是否已經開啓 * * @param context * @return */ public static boolean isWorked(Context context) { ActivityManager myManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); ArrayList<RunningServiceInfo> runningService = (ArrayList<RunningServiceInfo>) myManager .getRunningServices(30); for (int i = 0; i < runningService.size(); i++) { if (runningService.get(i).service.getClassName().toString() .equals("com.XXXX.service")) { LogUtil.i(TAG, "Service is run"); return true; } } LogUtil.i(TAG, "Service is not run"); return false; }