Exemplo n.º 1
0
 private boolean checkConnectivity() {
   boolean mobile =
       mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected();
   boolean wifi = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
   Log.d(LOGT, "Connectivity: Mobile: " + mobile + " WiFi: " + wifi);
   return mobile || wifi;
 }
  public static boolean isConnected(Context context) {
    ConnectivityManager cm =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    return cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting()
        || cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
  }
Exemplo n.º 3
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.add:
        // click on about item
        Log.i("TAG", "ADD");
        ConnectivityManager connec =
            (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connec != null && (connec.getNetworkInfo(1).isAvailable() == true)
            || (connec.getNetworkInfo(0).isAvailable() == true)) {
          Intent i = new Intent(getApplicationContext(), AddFriend.class);
          startActivity(i);
        } else {
          Toast toast = Toast.makeText(this, "NO CONNECTION", Toast.LENGTH_SHORT);
          toast.show();
        }
        break;

      case R.id.home:
        // click on about item
        Log.i("TAG", "HOME");
        Intent ii = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(ii);
        break;
    }
    return true;
  }
Exemplo n.º 4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ConnectivityManager connec =
        (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connec != null && (connec.getNetworkInfo(1).isAvailable() == true)
        || (connec.getNetworkInfo(0).isAvailable() == true)) {
      this.setTitle("New Friend..");

      Parse.initialize(
          this,
          "PV07xPdLpxzJKBKUS2UP6iJ0W9GbEHvmfPMMQovz",
          "OPxrcJKt4Pe26WHvCAeuI86hnGzXjOlO1NmyfJyP");

      WebView myWebView = (WebView) findViewById(R.id.webView1);
      myWebView.loadUrl("http://www.markevansjr.com/AndroidApp/index.html");

      WebSettings webSettings = myWebView.getSettings();
      webSettings.setJavaScriptEnabled(true);
      myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");

      myWebView.setWebViewClient(new WebViewClient());
    } else {
      Toast toast = Toast.makeText(this, "NO CONNECTION", Toast.LENGTH_SHORT);
      toast.show();
    }
  }
Exemplo n.º 5
0
  public static boolean isOnline(final Context context) {
    final ConnectivityManager connMgr =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    if (wifi.isConnected()) {

      //	 Toast.makeText(context, "Wifi" , Toast.LENGTH_LONG).show();
      return true;
    } else if (mobile.isConnected()) {

      // Toast.makeText(context, "Mobile 3G " , Toast.LENGTH_LONG).show();
      return true;
    } else {
      ((Activity) context)
          .runOnUiThread(
              new Runnable() {
                public void run() {
                  Toast.makeText(context, "No Network ", 5000).show();
                }
              });
      return false;
    }
  }
Exemplo n.º 6
0
  @Override
  public void onReceive(Context context, Intent intent) {
    ConnectivityManager connectivityManager =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    NetworkInfo activeWifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo activeHighNetInfo =
        connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_HIPRI);

    boolean isMobileConnected = activeNetInfo != null && activeNetInfo.isConnectedOrConnecting();

    boolean isHighSpeedConnected =
        activeHighNetInfo != null && activeHighNetInfo.isConnectedOrConnecting();

    boolean isWifiConnected = activeWifiInfo != null && activeWifiInfo.isConnectedOrConnecting();
    if (isWifiConnected || isMobileConnected || isHighSpeedConnected) {
      if (ApplicationLoader.getPreferences().isLoggedIn()) {
        if (!ApplicationLoader.getPreferences().isPullAlarmService()) {
          SessionManagement sm = new SessionManagement(context);
          sm.getLastIdFromPreferences();
          ApplicationLoader.setAlarm();
        }
        if (TextUtils.isEmpty(ApplicationLoader.getPreferences().getInstallationDate())) {
          ApplicationLoader.getPreferences().setInstallationDate(Utilities.getTodayDate());
        }
        context.startService(new Intent(context, PullAlarmService.class));
      }
    }
  }
  boolean isNetworkConnected(Context context) {
    ConnectivityManager cm =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if (ni != null) {
      Log.d("DemoLog", "!=null");
      try {
        // For 3G check
        boolean is3g = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
        // For WiFi Check
        boolean isWifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();

        Log.d("DemoLog", "isWifi=" + isWifi);
        Log.d("DemoLog", "is3g=" + is3g);
        if (!isWifi) {

          return false;
        } else {
          return true;
        }

      } catch (Exception er) {
        return false;
      }

    } else {
      Log.d("DemoLog", "==null");
      return false;
    }
  }
Exemplo n.º 8
0
  /**
   * 获取当前网络状态 返回2代表wifi,1代表2G/3G
   *
   * @param paramContext
   * @return
   */
  public static String[] getNetType(Context paramContext) {
    String[] arrayOfString = {"Unknown", "Unknown"};
    PackageManager localPackageManager = paramContext.getPackageManager();
    if (localPackageManager.checkPermission(
            "android.permission.ACCESS_NETWORK_STATE", paramContext.getPackageName())
        != 0) {
      arrayOfString[0] = "Unknown";
      return arrayOfString;
    }

    ConnectivityManager localConnectivityManager =
        (ConnectivityManager) paramContext.getSystemService("connectivity");
    if (localConnectivityManager == null) {
      arrayOfString[0] = "Unknown";
      return arrayOfString;
    }

    NetworkInfo localNetworkInfo1 = localConnectivityManager.getNetworkInfo(1);
    if (localNetworkInfo1 != null && localNetworkInfo1.getState() == NetworkInfo.State.CONNECTED) {
      arrayOfString[0] = "2";
      return arrayOfString;
    }

    NetworkInfo localNetworkInfo2 = localConnectivityManager.getNetworkInfo(0);
    if (localNetworkInfo2 != null && localNetworkInfo2.getState() == NetworkInfo.State.CONNECTED) {
      arrayOfString[0] = "1";
      arrayOfString[1] = localNetworkInfo2.getSubtypeName();
      return arrayOfString;
    }

    return arrayOfString;
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    Log.v(ApeicUtil.TAG_HTTP, "UploadCheckReceiver onReceive");

    ConnectivityManager connManager =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (!connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected()
        && !connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
      return;
    }

    File logFileFolder = new File(context.getFilesDir(), ApeicUtil.PENDING_LOG_FILES_FOLDER);
    if (logFileFolder.exists()) {
      Log.d(
          ApeicUtil.TAG_HTTP,
          "Num of files to be uploaded: " + String.valueOf(logFileFolder.listFiles().length));
      for (File file : logFileFolder.listFiles()) {
        Intent uploadIntent = new Intent(context, LogUploadIntentService.class);
        uploadIntent.putExtra("path", file.getAbsolutePath());
        context.startService(uploadIntent);
      }
    }

    Intent updateIntent = new Intent(context, UpdateInstalledAppsIntentService.class);
    context.startService(updateIntent);
  }
Exemplo n.º 10
0
 public static boolean isNetworkAvailable() {
   Boolean net = false;
   int Tcon =
       Integer.parseInt(
           PreferenceManager.getDefaultSharedPreferences(context).getString("t_conexion", "2"));
   ConnectivityManager connectivityManager =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   switch (Tcon) {
     case 0:
       NetworkInfo Wifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
       net = Wifi.isConnected();
       break;
     case 1:
       NetworkInfo mobile = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
       net = mobile.isConnected();
       break;
     case 2:
       NetworkInfo WifiA = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
       NetworkInfo mobileA = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
       net = WifiA.isConnected() || mobileA.isConnected();
       break;
   }
   NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
   return activeNetworkInfo != null && net;
 }
Exemplo n.º 11
0
 /**
  * 检查网络状态
  *
  * @return 1表示仅有 移动网络 2表示仅有wifi 3表示移动wifi都开通 4表示移动wifi都不通
  */
 public int checkNetwork() {
   if (Machine.isTablet(mContext)) {
     return 0;
   }
   ConnectivityManager conMan =
       (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (conMan == null) {
     return 0;
   }
   android.net.NetworkInfo.State mobilestate =
       conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
   android.net.NetworkInfo.State wifistate =
       conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
   if (wifistate != android.net.NetworkInfo.State.CONNECTED
       && mobilestate == android.net.NetworkInfo.State.CONNECTED) {
     return 1;
   }
   if (mobilestate != android.net.NetworkInfo.State.CONNECTED
       && wifistate == android.net.NetworkInfo.State.CONNECTED) {
     return 2;
   }
   if (mobilestate == android.net.NetworkInfo.State.CONNECTED
       && wifistate == android.net.NetworkInfo.State.CONNECTED) {
     return 3;
   }
   if (mobilestate != android.net.NetworkInfo.State.CONNECTED
       && wifistate != android.net.NetworkInfo.State.CONNECTED) {
     return 4;
   }
   return 0;
 }
Exemplo n.º 12
0
  @Override
  public void onReceive(Context context, Intent intent) {
    try {
      Log.i(ApplicationContextClient.class.getName(), "AlarmReceiver:" + intent.getAction());
    } catch (Exception e) {
      System.out.println("AlarmReceiver");
    }
    if (ACTION.equals(intent.getAction())) {
      // 心跳广播
      applicationContextClient.sendHeartBeatMessage();
    } else if (CONNECT_ACTION.equals(intent.getAction())) {
      // 重连广播监听
      try {
        NettyServerManager.reconnect();
      } catch (Exception e) {
        e.printStackTrace();
      }

    } else if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
      // 网络状态监听广播接收
      connectivityManager(context);
      NetworkInfo gprs = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
      NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
      if (!gprs.isConnected() && !wifi.isConnected()) {
        // 網絡斷開 了
        // 停止心跳消息发送
        NettyAlarmManager.stopHeart();
        // 停止重连
        NettyAlarmManager.stopReconnection();
      } else {
        // 启动重连
        NettyAlarmManager.startReconnection(context);
      }
    }
  }
Exemplo n.º 13
0
 /**
  * 网络是否手机网络连接
  *
  * @param context
  * @return
  */
 public static boolean isOnlyMobileType(Context context) {
   State wifiState = null;
   State mobileState = null;
   ConnectivityManager cm =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo networkInfo = null;
   try {
     networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
   } catch (Exception e) {
     e.printStackTrace();
   }
   if (networkInfo != null) {
     wifiState = networkInfo.getState();
   }
   try {
     networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
   } catch (Exception e) {
     e.printStackTrace();
   }
   if (networkInfo != null) {
     mobileState = networkInfo.getState();
   }
   LogS.d("zhang", "onReceive -- wifiState = " + wifiState + " -- mobileState = " + mobileState);
   if (wifiState != null
       && mobileState != null
       && State.CONNECTED != wifiState
       && State.CONNECTED == mobileState) {
     // 手机网络连接成功
     LogS.d("zhang", "onReceive -- 手机网络连接成功");
     return true;
   }
   return false;
 }
Exemplo n.º 14
0
 // �������������
 public static boolean checkNetworkInfo(Context mContext) {
   ConnectivityManager conMan =
       (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
   State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
   State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
   if (mobile == State.CONNECTED || mobile == State.CONNECTING) return true;
   if (wifi == State.CONNECTED || wifi == State.CONNECTING) return true;
   return false;
 }
 // Function to check the Internet Connection Status
 public boolean CheckInternet(Context ctx) {
   ConnectivityManager connec =
       (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo wifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
   NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
   // Check if wifi or mobile network is available or not. If any of them is
   // available or connected then it will return true, otherwise false;
   return wifi.isConnected() || mobile.isConnected();
 }
  /**
   * This method returns true, when network connectivity is available, either wifi or mobile
   *
   * @param context
   * @return
   */
  public static boolean checkStatus(Context context) {
    final ConnectivityManager connMgr =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    boolean networkAvailable = (wifi.isConnected() || mobile.isConnected());
    return networkAvailable;
  }
        @Override
        public void onReceive(Context context, Intent intent) {
          if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
            mdnsSd.stop();

            ConnectivityManager connManager =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            NetworkInfo mEth = connManager.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);

            NetworkInterface netInterface = null;
            // search the network interface with the ip address returned by the wifi manager
            if ((mWifi != null) && (mWifi.isConnected())) {
              WifiManager wifiManager =
                  (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
              if (wifiManager != null) {
                WifiInfo wifiInfo = wifiManager.getConnectionInfo();
                int ipAddressInt = wifiInfo.getIpAddress();
                String ipAddress =
                    String.format(
                        "%d.%d.%d.%d",
                        (ipAddressInt & 0xff),
                        (ipAddressInt >> 8 & 0xff),
                        (ipAddressInt >> 16 & 0xff),
                        (ipAddressInt >> 24 & 0xff));
                try {
                  InetAddress addr = InetAddress.getByName(ipAddress);
                  Enumeration<NetworkInterface> intfs = NetworkInterface.getNetworkInterfaces();
                  while (netInterface == null && intfs.hasMoreElements()) {
                    NetworkInterface intf = intfs.nextElement();
                    Enumeration<InetAddress> interfaceAddresses = intf.getInetAddresses();
                    while (netInterface == null && interfaceAddresses.hasMoreElements()) {
                      InetAddress interfaceAddr = interfaceAddresses.nextElement();
                      if (interfaceAddr.equals(addr)) {
                        netInterface = intf;
                      }
                    }
                  }
                } catch (Exception e) {
                  ARSALPrint.e(TAG, "Unable to get the wifi network interface", e);
                }
              }
            }

            // for ethernet, it's not possible to find the correct netInterface. Assume there is
            // a default route don't specify the netinterface
            if (((mWifi != null) && (mWifi.isConnected()))
                || ((mEth != null) && (mEth.isConnected()))) {
              ARSALPrint.v(TAG, "Restaring MdsnSd");
              mdnsSd.start(netInterface);
            } else {
              netDeviceServicesHmap.clear();
              broadcaster.broadcastDeviceServiceArrayUpdated();
            }
          }
        }
Exemplo n.º 18
0
 /**
  * 检查网络是否连接
  *
  * @return boolean
  */
 public boolean ifConnect() {
   ConnectivityManager con = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
   boolean wifi = con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
   boolean internet =
       con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
   if (wifi || internet) {
     return true;
   } else {
     return false;
   }
 }
  // This method checks for Network Connection(both Wifi and mobile). Return false if device is not
  // connected to any network.
  public boolean isOnline() {

    ConnectivityManager connMgr =
        (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    boolean isWifiConn = networkInfo.isConnected();
    networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    boolean isMobileConn = networkInfo.isConnected();

    return (isWifiConn || isMobileConn);
  }
Exemplo n.º 20
0
 public static boolean isNetworkAvailable(Context context) {
   ConnectivityManager connectivityManager =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
   NetworkInfo wifiNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
   // connectivityManager.getActiveNetworkInfo();
   if (!mobNetInfo.isConnected() && !wifiNetInfo.isConnected()) {
     return false;
   } else {
     return true;
   }
 }
Exemplo n.º 21
0
  private boolean hasNetworkConnection() {
    ConnectivityManager connectivityManager =
        (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    boolean isWifiAvailable = networkInfo.isAvailable();
    boolean isWifiConnected = networkInfo.isConnected();
    networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    boolean isMobileAvailable = networkInfo.isAvailable();
    boolean isMobileConnnected = networkInfo.isConnected();

    return (isWifiAvailable && isWifiConnected) || (isMobileAvailable && isMobileConnnected);
  }
Exemplo n.º 22
0
 public static boolean isOnline() {
   try {
     ConnectivityManager conMgr =
         (ConnectivityManager) ofActivity.getSystemService(Context.CONNECTIVITY_SERVICE);
     return conMgr != null
         && (conMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState()
                 == NetworkInfo.State.CONNECTED
             || conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState()
                 == NetworkInfo.State.CONNECTED);
   } catch (Exception e) {
     return false;
   }
 }
Exemplo n.º 23
0
 /**
  * �?��当前网络连接状�?
  *
  * @param 调用此方法的Context
  * @return true - 有可用的网络连接�?G/GSM、wifi等) false - 没有可用的网络连接,或传入的context为null
  */
 public static boolean isNetworkConnected(Context context) {
   if (context == null) {
     return false;
   }
   ConnectivityManager connManager =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   State mobileState = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
   State wifiState = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
   if (mobileState == State.DISCONNECTED && wifiState == State.DISCONNECTED) {
     return false;
   }
   return true;
 }
Exemplo n.º 24
0
 public static boolean internetConnection(Context context) {
   ConnectivityManager connManager =
       (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
   String WIFI =
       String.valueOf(connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState());
   String MOBILE =
       String.valueOf(connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState());
   if (WIFI == "CONNECTED" || MOBILE == "CONNECTED") {
     return true;
   } else {
     return false;
   }
 }
Exemplo n.º 25
0
 public int getConnectivityType(Context con) {
   int type = CONNECTIVITY_TYPE_NONE;
   try {
     ConnectivityManager connectivityManager =
         (ConnectivityManager) con.getSystemService(Context.CONNECTIVITY_SERVICE);
     NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
     NetworkInfo mobileInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
     if (wifiInfo.isConnected()) type = CONNECTIVITY_TYPE_WIFI;
     else if (mobileInfo.isConnected()) type = CONNECTIVITY_TYPE_MOBILE;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return type;
 }
Exemplo n.º 26
0
 public static Boolean cheakConnect(Context context, Activity activity) {
   ConnectivityManager connectivityManager =
       (ConnectivityManager) context.getSystemService(activity.CONNECTIVITY_SERVICE);
   NetworkInfo info1 = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
   NetworkInfo info2 = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
   if ((info1 != null) && (info1.isAvailable()) || (info2.isAvailable())) {
     if ((info1.isConnected()) || (info2.isConnected())) {
       return true;
     } else {
       return false;
     }
   }
   return false;
 }
Exemplo n.º 27
0
 /**
  * 添加网络检查
  *
  * @return
  */
 public boolean checkNetwork() {
   if (con == null) {
     con = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
   }
   boolean wifi = con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
   boolean internet =
       con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
   if (!wifi && !internet) {
     showInfo(R.string.network_check_error);
     return false;
   } else {
     return true;
   }
 }
Exemplo n.º 28
0
 private boolean isNetworkAvailable() {
   ConnectivityManager connec =
       (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo mobileInfo = connec.getNetworkInfo(0);
   NetworkInfo wifiInfo = connec.getNetworkInfo(1);
   NetworkInfo wimaxInfo = connec.getNetworkInfo(6);
   boolean bm = false;
   boolean bw = false;
   boolean bx = false;
   if (mobileInfo != null) bm = mobileInfo.isConnected();
   if (wimaxInfo != null) bx = wimaxInfo.isConnected();
   if (wifiInfo != null) bw = wifiInfo.isConnected();
   return (bm || bw || bx);
 }
Exemplo n.º 29
0
  public Boolean isNetAvailable(Context con) {

    try {
      ConnectivityManager connectivityManager =
          (ConnectivityManager) con.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
      NetworkInfo mobileInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
      if (wifiInfo.isConnected() || mobileInfo.isConnected()) {
        return true;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return false;
  }
 private static String a(Context context)
 {
     ConnectivityManager connectivitymanager = (ConnectivityManager)context.getSystemService("connectivity");
     if (connectivitymanager.getNetworkInfo(1).isConnectedOrConnecting())
     {
         return "WIFI";
     }
     if (connectivitymanager.getNetworkInfo(0).isConnectedOrConnecting())
     {
         return "MOBILE";
     } else
     {
         return "unkown";
     }
 }