zoukankan      html  css  js  c++  java
  • Android——显示当前运行所有服务,判断服务是否运行

    1.显示系统当前所有运行服务:

    ActivityManager am = (ActivityManager) MainActivity.this.getSystemService(Context.ACTIVITY_SERVICE);
            for (RunningServiceInfo service : am.getRunningServices(Integer.MAX_VALUE)) {
                System.out.println(service.service.getPackageName()+"-----"+service.service.getClassName());
            }

    2.判断某一个服务是否运行:

    public static boolean checkServiceStatus(Context context) {
            boolean isServiceRunning = false;
            ActivityManager am = (ActivityManager) context
                    .getSystemService(Context.ACTIVITY_SERVICE);
            for (RunningServiceInfo service : am
                    .getRunningServices(Integer.MAX_VALUE)) {
                if (BackgroundService.class.getName().equals(service.service.getClassName())) {
                    isServiceRunning = true;
                    break;
                }
            }
            return isServiceRunning;
        }
  • 相关阅读:
    visual sudio开发工具使用小技巧
    JS去除右边的逗号
    下拉标题
    sp_addextendedproperty
    触发器的使用
    缺失一个正数
    组合总和 去重
    拖动 Drag
    n皇后问题
    括号生成
  • 原文地址:https://www.cnblogs.com/sishuiliuyun/p/3243313.html
Copyright © 2011-2022 走看看