Example #1
0
  public static boolean isNetworkAvailable1(Activity activity) {
    {
      Log.i("Context", "value of Activity is " + activity);
      System.out.println("hi eerror");
      boolean haveConnectedWifi = false;
      boolean haveConnectedMobile = false;

      ConnectivityManager cm =
          (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo[] netInfo = cm.getAllNetworkInfo();
      for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI")) {
          if (ni.isConnected()) {
            haveConnectedWifi = true;
            Log.v("WIFI CONNECTION ", "AVAILABLE");
          } else {
            Log.v("WIFI CONNECTION ", "NOT AVAILABLE");
          }
        }
        if (ni.getTypeName().equalsIgnoreCase("MOBILE")) {
          if (ni.isConnected()) {
            haveConnectedMobile = true;
            Log.v("MOBILE INTERNET CONNECTION ", "AVAILABLE");
          } else {
            Log.v("MOBILE INTERNET CONNECTION ", "NOT AVAILABLE");
          }
        }
      }
      return haveConnectedWifi || haveConnectedMobile;
    }
  }
Example #2
0
 /**
  * Check the netwoek is enable
  *
  * @param context Access to {@code ConnectivityManager} services
  * @return Available returns true, unavailable returns false
  */
 @SuppressWarnings("deprecation")
 @SuppressLint("NewApi")
 public static boolean isNetworkAvailable(Context context) {
   try {
     ConnectivityManager connectivity =
         (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     if (connectivity == null) {
       return false;
     } else {
       if (VERSION.SDK_INT >= 21) {
         Network[] networks = connectivity.getAllNetworks();
         for (Network network : networks) {
           NetworkInfo networkInfo = connectivity.getNetworkInfo(network);
           if (networkInfo.getState() == NetworkInfo.State.CONNECTED) return true;
         }
       } else {
         NetworkInfo[] networkInfos = connectivity.getAllNetworkInfo();
         for (NetworkInfo networkInfo : networkInfos)
           if (networkInfo.getState() == NetworkInfo.State.CONNECTED) return true;
       }
     }
   } catch (Throwable e) {
     Logger.throwable(e);
   }
   return false;
 }
  private boolean checkUplink() {

    Log.v(TAG, "Dentro CheckupLink()");

    if (!app.prefs.getBoolean("wan_start", false)) { // se la wan è disabilitata niente check
      Log.v(TAG, "Dentro CheckupLink(), WanStart False");
      return true;
    }
    if (app.prefs.getBoolean("wan_nowait", false)) {
      Log.v(TAG, "Dentro CheckupLink(), Wan_NoWait True");
      return true;
    }

    // NetworkInfo mobileInfo =connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    NetworkInfo wimaxInfo = connManager.getNetworkInfo(6);
    Log.v(TAG, "Dentro CheckupLink(), prima del return");
    // Cerco se esiste una interfaccia UMTS
    NetworkInfo[] info = connManager.getAllNetworkInfo();
    boolean umts = false;
    if (info != null) {
      for (int i = 0; i < info.length; i++) {
        if (info[i].getType() == connManager.TYPE_MOBILE) {
          // log(true, "Hspa interface "+info[i].getSubtypeName()+" found");
          if (info[i].getState() == NetworkInfo.State.CONNECTED) umts = true;
        }
      }
    }
    return (umts || ((wimaxInfo != null) && wimaxInfo.isConnected()));
  }
Example #4
0
 /**
  * 打印当前各种网络状态
  *
  * @return boolean
  */
 public static boolean printNetworkInfo(Context context) {
   ConnectivityManager connectivity =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (connectivity != null) {
     NetworkInfo in = connectivity.getActiveNetworkInfo();
     Log.i(TAG, "-------------$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$-------------");
     Log.i(TAG, "getActiveNetworkInfo: " + in);
     NetworkInfo[] info = connectivity.getAllNetworkInfo();
     if (info != null) {
       for (int i = 0; i < info.length; i++) {
         // if (info[i].getType() == ConnectivityManager.TYPE_WIFI) {
         Log.i(TAG, "NetworkInfo[" + i + "]isAvailable : " + info[i].isAvailable());
         Log.i(TAG, "NetworkInfo[" + i + "]isConnected : " + info[i].isConnected());
         Log.i(
             TAG,
             "NetworkInfo["
                 + i
                 + "]isConnectedOrConnecting : "
                 + info[i].isConnectedOrConnecting());
         Log.i(TAG, "NetworkInfo[" + i + "]: " + info[i]);
         // }
       }
       Log.i(TAG, "\n");
     } else {
       Log.i(TAG, "getAllNetworkInfo is null");
     }
   }
   return false;
 }
Example #5
0
 private void isConnectedNetwork() {
   ConnectivityManager cm =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (cm == null) {
     mIsConnected = false;
     return;
   }
   NetworkInfo[] netInfo = cm.getAllNetworkInfo();
   if (netInfo == null) {
     mIsConnected = false;
     return;
   }
   for (NetworkInfo ni : netInfo) {
     if (ni.getTypeName().equalsIgnoreCase("WIFI"))
       if (ni.isConnected()) {
         Log.d(this.toString(), "test: wifi conncetion found");
         mIsConnected = true;
         return;
       }
     if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
       if (ni.isConnected()) {
         Log.d(this.toString(), "test: mobile connection found");
         mIsConnected = true;
         return;
       }
   }
   mIsConnected = false;
   return;
 }
  @Override
  public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    ConnectivityManager manager =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    mState = State.NOT_CONNECTED;

    NetworkInfo[] nInfos = manager.getAllNetworkInfo();
    for (NetworkInfo nInfo : nInfos) {
      if (nInfo.isConnectedOrConnecting()) {
        mNetworkInfo = nInfo;
        mState = State.CONNECTED;
        break;
      }
    }

    if (mHandlers != null) {
      // Notifiy any handlers.
      Iterator<Handler> it = mHandlers.keySet().iterator();
      while (it.hasNext()) {
        Handler target = it.next();
        Message message = Message.obtain(target, mHandlers.get(target));
        target.sendMessage(message);
      }
    }
  }
Example #7
0
 /**
  * whether there is only one network connected. {@link android.net.ConnectivityManager#TYPE_WIFI}
  * {@link android.net.ConnectivityManager#TYPE_MOBILE}
  *
  * @param ctx
  * @return
  */
 public static boolean onlyOneNetWork(Context ctx) {
   if (ctx == null) return false;
   ConnectivityManager manager =
       (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (manager == null) return false;
   NetworkInfo[] infos = manager.getAllNetworkInfo();
   int count = 0;
   if (infos == null) return false;
   for (NetworkInfo info : infos) if (info.isConnected()) count++;
   return count == 1;
 }
Example #8
0
 public static boolean isConnected(Context context) {
   ConnectivityManager cm =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo[] NI = cm.getAllNetworkInfo();
   for (int i = 0; i < NI.length; i++) {
     if (NI[i].isConnected()) {
       return true;
     }
   }
   return false;
 }
 public static boolean isConnected() {
   ConnectivityManager conMgr =
       (ConnectivityManager) OMWPP.CONTEXT.getSystemService(Context.CONNECTIVITY_SERVICE);
   boolean result = false;
   for (NetworkInfo ni : conMgr.getAllNetworkInfo()) {
     if (ni.isConnected()) {
       result = true;
       break;
     }
   }
   return result;
 }
Example #10
0
  // this is to check the internet connection available
  // 0 = no connection
  // 1 = Mobile connection
  // 2 Wifi connection
  public int HaveNetworkConnection() {

    int connectionType = 0;

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
      if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) connectionType = 3;
      if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) connectionType = 1;
    }
    return connectionType;
  }
Example #11
0
  private boolean isNetworkAvailable() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
      if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true;
      if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
        if (ni.isConnected()) haveConnectedMobile = true;
    }
    return haveConnectedWifi || haveConnectedMobile;
  }
Example #12
0
 /**
  * 网络是否可用
  *
  * @param context
  * @return
  */
 public static boolean isNetworkAvailable(Context context) {
   ConnectivityManager mgr =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo[] info = mgr.getAllNetworkInfo();
   if (info != null) {
     for (int i = 0; i < info.length; i++) {
       if (info[i].getState() == NetworkInfo.State.CONNECTED) {
         return true;
       }
     }
   }
   return false;
 }
Example #13
0
 public boolean isConnectingToInternet() {
   ConnectivityManager connectivity =
       (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (connectivity != null) {
     NetworkInfo[] info = connectivity.getAllNetworkInfo();
     if (info != null)
       for (int i = 0; i < info.length; i++)
         if (info[i].getState() == NetworkInfo.State.CONNECTED) {
           return true;
         }
   }
   return false;
 }
Example #14
0
 // para chequear si tiene conexion a internet
 public static boolean verificaConexion(Context ctx) {
   boolean bConectado = false;
   ConnectivityManager connec =
       (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
   // No sólo wifi, también GPRS
   NetworkInfo[] redes = connec.getAllNetworkInfo();
   for (int i = 0; i < 2; i++) {
     // true si hay conexión
     if (redes[i].getState() == NetworkInfo.State.CONNECTED) {
       bConectado = true;
     }
   }
   return bConectado;
 }
  public boolean checkConexaoInternet(Context c) {
    ConnectivityManager connectivity =
        (ConnectivityManager) getApplicationContext().getSystemService(c.CONNECTIVITY_SERVICE);

    if (connectivity != null) {
      NetworkInfo[] inf = connectivity.getAllNetworkInfo();
      if (inf != null)
        for (int i = 0; i < inf.length; i++)
          if (inf[i].getState() == NetworkInfo.State.CONNECTED) {
            return true;
          }
    }
    return false;
  }
Example #16
0
 /**
  * @Title: isNet @Description: 检查当前网络是否可用
  *
  * @param @param pContext
  * @param @return
  * @return boolean true 可用,false 不可用
  * @throws
  */
 public static boolean isNet(Context pContext) {
   ConnectivityManager _Manager =
       (ConnectivityManager) pContext.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo networkInfo[] = _Manager.getAllNetworkInfo();
   // 注意,这个判断一定要的哦,要不然会出错
   if (networkInfo != null) {
     for (int i = 0; i < networkInfo.length; i++) {
       if (networkInfo[i].getState() == NetworkInfo.State.CONNECTED) {
         return true;
       }
     }
   }
   return false;
 }
Example #17
0
  // controllo connessione
  public boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    @SuppressWarnings("static-access")
    ConnectivityManager cm =
        (ConnectivityManager) getActivity().getSystemService(getActivity().CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
      if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true;
      if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
        if (ni.isConnected()) haveConnectedMobile = true;
    }
    return haveConnectedWifi || haveConnectedMobile;
  }
 public static boolean isNetWorkConnected(Context context) {
   ConnectivityManager cm =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo[] nis = cm.getAllNetworkInfo();
   if (nis != null) {
     for (NetworkInfo ni : nis) {
       if (ni != null) {
         if (ni.isConnected()) {
           return true;
         }
       }
     }
   }
   return false;
 }
Example #19
0
 public boolean CheckNetwork(Context context) {
   ConnectivityManager connectivity =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (connectivity != null) {
     NetworkInfo[] info = connectivity.getAllNetworkInfo();
     if (info != null) {
       for (int i = 0; i < info.length; i++) {
         if (info[i].getState() == NetworkInfo.State.CONNECTED) {
           return true;
         }
       }
     }
   }
   return false;
 }
Example #20
0
 public static boolean isNetworkAvailable(Context context) {
   ConnectivityManager connectivityManager =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (connectivityManager != null) {
     NetworkInfo[] allNetworkInfo = connectivityManager.getAllNetworkInfo();
     if (allNetworkInfo != null) {
       for (NetworkInfo networkInfo : allNetworkInfo) {
         if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {
           return true;
         }
       }
     }
   }
   return false;
 }
 /**
  * 检测网络是否连接
  *
  * @return
  */
 public boolean isNetConnected() {
   ConnectivityManager cm =
       (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (cm != null) {
     NetworkInfo[] infos = cm.getAllNetworkInfo();
     if (infos != null) {
       for (NetworkInfo ni : infos) {
         if (ni.isConnected()) {
           return true;
         }
       }
     }
   }
   return false;
 }
Example #22
0
  // check Internet conenction.
  private void checkInternetConenction() {
    ConnectivityManager check =
        (ConnectivityManager) this.context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (check != null) {
      NetworkInfo[] info = check.getAllNetworkInfo();
      if (info != null)
        for (int i = 0; i < info.length; i++)
          if (info[i].getState() == NetworkInfo.State.CONNECTED) {
            Toast.makeText(context, "Internet is connected", Toast.LENGTH_SHORT).show();
          }

    } else {
      Toast.makeText(context, "not conencted to internet", Toast.LENGTH_SHORT).show();
    }
  }
  public static boolean isNetWorkAvailable(Context context) {
    ConnectivityManager connec =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connec == null) return false;

    NetworkInfo[] allinfo = connec.getAllNetworkInfo();
    if (allinfo != null) {
      for (int i = 0; i < allinfo.length; i++) {
        if (allinfo[i].isAvailable() && allinfo[i].isConnected()) {
          return true;
        }
      }
    }
    return false;
  }
 public static boolean isWiFiActive(Context inContext) {
   Context context = inContext.getApplicationContext();
   ConnectivityManager connectivity =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (connectivity != null) {
     NetworkInfo[] info = connectivity.getAllNetworkInfo();
     if (info != null) {
       for (int i = 0; i < info.length; i++) {
         if (info[i].getTypeName().equals("WIFI") && info[i].isConnected()) {
           return true;
         }
       }
     }
   }
   return false;
 }
Example #25
0
 public static boolean isWifiConnected(Context c) {
   if (c != null) {
     ConnectivityManager connManager =
         (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
     NetworkInfo[] connections = connManager.getAllNetworkInfo();
     int count = connections.length;
     for (int i = 0; i < count; i++)
       if (connections[i] != null
               && connections[i].getType() == ConnectivityManager.TYPE_WIFI
               && connections[i].isConnectedOrConnecting()
           || connections[i] != null
               && connections[i].getType() == ConnectivityManager.TYPE_ETHERNET
               && connections[i].isConnectedOrConnecting()) return true;
   }
   return false;
 }
  public static boolean hasIC(Context context) {
    // http://stackoverflow.com/questions/4238921/detect-whether-there-is-an-internet-connection-available-on-android

    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
      if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) haveConnectedWifi = true;
      if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
        if (ni.isConnected()) haveConnectedMobile = true;
    }
    return haveConnectedWifi || haveConnectedMobile;
  }
Example #27
0
 public static boolean isNetOk(Context context) {
   ConnectivityManager connectivityManager =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (connectivityManager != null) {
     NetworkInfo[] networkInfos = connectivityManager.getAllNetworkInfo();
     for (int i = 0; i < networkInfos.length; i++) {
       NetworkInfo.State state = networkInfos[i].getState();
       Log.e("NetStateBroadCast", "" + state.name());
       if (NetworkInfo.State.CONNECTED == state) {
         return true;
       }
     }
   }
   // 没有执行return,则说明当前无网络连接
   Log.e("NetStateBroadCast", "------------> Network is validate");
   return false;
 }
Example #28
0
 /**
  * 判断网络是否可用
  *
  * @param context
  * @return
  */
 public static boolean isNetworkAvailable(Context context) {
   ConnectivityManager cm =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (cm != null) {
     // 如果仅仅是用来判断网络连接
     // 则可以使用 cm.getActiveNetworkInfo().isAvailable();
     NetworkInfo[] info = cm.getAllNetworkInfo();
     if (info != null) {
       for (int i = 0; i < info.length; i++) {
         if (info[i].getState() == NetworkInfo.State.CONNECTED) {
           return true;
         }
       }
     }
   }
   return false;
 }
 public static boolean haveNetworkConnection(Context activity) {
   ConnectivityManager connectivity =
       (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (connectivity == null) {
     return false;
   } else {
     NetworkInfo[] info = connectivity.getAllNetworkInfo();
     if (info != null) {
       for (int i = 0; i < info.length; i++) {
         if (info[i].getState() == NetworkInfo.State.CONNECTED) {
           return true;
         }
       }
     }
   }
   return false;
 }
  public boolean available() {
    ConnectivityManager conex =
        (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (conex != null) {
      NetworkInfo[] info = conex.getAllNetworkInfo();

      for (int i = 0; i < info.length; i++) {
        if (info[i].getState() == NetworkInfo.State.CONNECTED
            && info[i].isConnectedOrConnecting()) {
          return true;
        }
      }
    }
    Toast t = Toast.makeText(ctx, "No tenemos conexi�n", Toast.LENGTH_LONG);
    t.show();
    return false;
  }