zoukankan      html  css  js  c++  java
  • ServiceManager

    public static boolean isActivityRunning(Context mContext) {
            ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
            List<RunningTaskInfo> info = activityManager.getRunningTasks(1);
            if (info != null && info.size() > 0) {
                ComponentName component = info.get(0).topActivity;
                if ("com.example.similarforward.MainActivity".endsWith(component.getClassName())) {
                    return true;
                }
            }
            return false;
        }
    public static boolean isServiceRunning(Context mContext) {
            boolean isRunning = false;
            ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
            List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(30);
    
            if (!(serviceList.size() > 0)) {
                return false;
            }
    
            for (int i = 0; i < serviceList.size(); i++) {
                if (serviceList.get(i).service.getClassName().equals("com.example.similarforward.SocketService") == true) {
                    isRunning = true;
    
                    break;
                }
            }
            return isRunning;
        }
    //判断是否有网
            public static boolean isNetWork(Context context) {    
                ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
                // 检查网络连接,如果无网络可用,就不需要进行连网操作等
                NetworkInfo info = manager.getActiveNetworkInfo();
                if (info == null || !manager.getBackgroundDataSetting()) {
    
                    return false;
                } else {
    
                    return true;
                }
    
            }
  • 相关阅读:
    51nod——T1267 4个数和为0
    cf220B莫队
    cf220b
    poj1436水平可见线
    poj2528贴海报,,
    poj3468
    hdu1698
    ural1989 单点更新+字符串hash
    cf Queries on a String
    hdu4605
  • 原文地址:https://www.cnblogs.com/g-sheng/p/5412227.html
Copyright © 2011-2022 走看看