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;
                }
    
            }
  • 相关阅读:
    poj 2100 尺取法 一个数字拆成连续数字平方和
    poj 1011 dfs+剪枝
    CF-242-C bfs+stl
    hdu 1297 递推
    poj 2104 划分树模板
    poj 3842 全排列+筛素数+暴力
    hdu 1421 经典dp
    hdu 1069 最长上升子序列变形
    hdu 3496 二维费用的01背包
    nyoj 16 最长上升子序列变形
  • 原文地址:https://www.cnblogs.com/g-sheng/p/5412227.html
Copyright © 2011-2022 走看看