File tree 1 file changed +10
-10
lines changed
1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change 1
- # 未归类
2
- ### 获取服务是否开启
1
+ # 未归类
2
+ ### 获取服务是否开启
3
3
```
4
4
/**
5
- * 获取服务是否开启
5
+ * 获取服务是否开启
6
6
*/
7
7
public static boolean isRunningService(String className, Context context) {
8
- //进程的管理者,活动的管理者
8
+ //进程的管理者,活动的管理者
9
9
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
+ //遍历集合
13
13
for (RunningServiceInfo runningServiceInfo : runningServices) {
14
- //获取控件的标示
14
+ //获取控件的标示
15
15
ComponentName service = runningServiceInfo.service;
16
- //获取正在运行的服务的全类名
16
+ //获取正在运行的服务的全类名
17
17
String className2 = service.getClassName();
18
- //将获取到的正在运行的服务的全类名和传递过来的服务的全类名比较,一直表示服务正在运行 返回true,不一致表示服务没有运行 返回false
18
+ //将获取到的正在运行的服务的全类名和传递过来的服务的全类名比较,一直表示服务正在运行 返回true,不一致表示服务没有运行 返回false
19
19
if (className.equals(className2)) {
20
20
return true;
21
21
}
You can’t perform that action at this time.
0 commit comments