File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # 未归类
2- ### 获取服务是否开启
1+ # 未归类
2+ ### 获取服务是否开启
33```
44/**
5- * 获取服务是否开启
5+ * 获取服务是否开启
66*/
77public static boolean isRunningService(String className, Context context) {
8- //进程的管理者,活动的管理者
8+ //进程的管理者,活动的管理者
99 ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
10- //获取正在运行的服务
11- List<RunningServiceInfo> runningServices = activityManager.getRunningServices(1000);//maxNum 返回正在运行的服务的上限个数,最多返回多少个服务
12- //遍历集合
10+ //获取正在运行的服务
11+ List<RunningServiceInfo> runningServices = activityManager.getRunningServices(1000);//maxNum 返回正在运行的服务的上限个数,最多返回多少个服务
12+ //遍历集合
1313 for (RunningServiceInfo runningServiceInfo : runningServices) {
14- //获取控件的标示
14+ //获取控件的标示
1515 ComponentName service = runningServiceInfo.service;
16- //获取正在运行的服务的全类名
16+ //获取正在运行的服务的全类名
1717 String className2 = service.getClassName();
18- //将获取到的正在运行的服务的全类名和传递过来的服务的全类名比较,一直表示服务正在运行 返回true,不一致表示服务没有运行 返回false
18+ //将获取到的正在运行的服务的全类名和传递过来的服务的全类名比较,一直表示服务正在运行 返回true,不一致表示服务没有运行 返回false
1919 if (className.equals(className2)) {
2020 return true;
2121 }
You can’t perform that action at this time.
0 commit comments