Exemplo n.º 1
1
  /**
   * @info Γίνεται έλεγχος για το αν υπάρχει σύνδεση της συσκευής μας με το internet(wifi ή 3G),
   *     καθώς και αν το gps είναι ανοικτό.
   * @details Χρησιμοποιούμε τις ενσωματωμένες κλάσεις του android
   *     (LocationManager,ConnectivityManager), για να ελέγξουμε αν υπάρχει ενεργή συνδεσιμότητα
   * @return true : Αν είναι ανοικτό το GPS και έχουμε πρόσβαση στο internet false : Αν δεν ισχύει
   *     έστω και ένα από τα παραπάνω
   */
  private boolean isConnectingToInternet(Activity activContext) {

    try {
      LocationManager GpsSservice =
          (LocationManager) activContext.getSystemService(Context.LOCATION_SERVICE);
      ConnectivityManager connManager =
          (ConnectivityManager) activContext.getSystemService(Context.CONNECTIVITY_SERVICE);
      boolean GpsEnabled = GpsSservice.isProviderEnabled(LocationManager.GPS_PROVIDER);
      NetworkInfo info = connManager.getActiveNetworkInfo();

      if (!GpsEnabled) {

        return false;
      } else if (info.getState() != NetworkInfo.State.CONNECTED) {

        return false;
      }

    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }

    return true;
  }
Exemplo n.º 2
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.º 3
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;
  }
Exemplo n.º 4
0
  @Override
  public void onReceive(Context context, Intent intent) {
    if (prefs == null) {
      prefs = context.getSharedPreferences("serval", 0);
    }

    if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
      ConnectivityManager connManager =
          (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

      NetworkInfo info =
          (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
      int opp =
          (info.getType() == ConnectivityManager.TYPE_WIFI)
              ? ConnectivityManager.TYPE_MOBILE
              : ConnectivityManager.TYPE_WIFI;
      NetworkInfo other = connManager.getNetworkInfo(opp);
      Map<String, ?> idMap = prefs.getAll();

      /* Connected, add rules back */
      if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
        performAction(context, idMap, AppHostCtrl.SERVICE_REMOVE);
        performAction(context, idMap, AppHostCtrl.SERVICE_ADD);
      }
      /* Disconnected, remove rules */
      else if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
        performAction(context, idMap, AppHostCtrl.SERVICE_REMOVE);

        /* Make rules available, since other interface is up */
        if (other.isConnectedOrConnecting()) {
          performAction(context, idMap, AppHostCtrl.SERVICE_ADD);
        }
      }
    }
  }
Exemplo n.º 5
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 void handleNetworkStateChanged(NetworkInfo parcelableExtra) {
    // TODO Auto-generated method stub
    Log.d(TAG, "handle NetworkStateChanged " + parcelableExtra.getState());
    State ns = parcelableExtra.getState();
    if (ns == NetworkInfo.State.DISCONNECTED) {
      // handle network disconnected

    }
  }
Exemplo n.º 7
0
 public static Type getConnectedNetworkType(Context context) {
   NetworkInfo networkInfo = getConnectManager(context).getActiveNetworkInfo();
   if (networkInfo == null || networkInfo.getState() != NetworkInfo.State.CONNECTED) {
     return Type.NO_NET;
   }
   return getType(networkInfo);
 }
Exemplo n.º 8
0
 public static boolean isNetConnected(Context context) {
   NetworkInfo networkInfo = getConnectManager(context).getActiveNetworkInfo();
   if (networkInfo == null) {
     return false;
   }
   return networkInfo.getState() == NetworkInfo.State.CONNECTED;
 }
Exemplo n.º 9
0
  /** Do the autoconnect stuff */
  private void autoconnect() {
    // If we don't have any servers to go with.
    if (Atomic.getInstance().getServersAsArrayList().size() < 1) return;
    // Or we've done this already
    if (!doAutoconnect.getValue()) return;
    // We don't need to get this far.

    // Are we connected to the greater wide not-us?
    NetworkInfo ninf =
        ((ConnectivityManager) (this.getSystemService(Service.CONNECTIVITY_SERVICE)))
            .getActiveNetworkInfo();
    // If there's no way out, or we aren't actually connected,
    if (ninf == null || ninf.getState() != NetworkInfo.State.CONNECTED) {
      // We don't need to bother, but we should say something.
      Toast.makeText(this, "Autoconnect skipped due to network outage", Toast.LENGTH_LONG).show();
      return;
    }
    // Some slime...
    Log.d("ServerList", "Doing autoconnect");
    for (int idx = 0; idx < adapter.getCount(); idx++) {
      Server s = adapter.getItem(idx);
      if (s.getAutoconnect() && s.getStatus() == Status.DISCONNECTED) {
        ConnectServer(s);
      }
    }
  }
Exemplo n.º 10
0
  public static State getNetworkState(Context context) {
    NetworkInfo networkInfo = getConnectManager(context).getActiveNetworkInfo();
    if (networkInfo == null) return State.DISCONNECTED;

    State state = State.UNKNOWN;

    switch (networkInfo.getState()) {
      case CONNECTING:
        state = State.CONNECTING;
        break;
      case CONNECTED:
        state = State.CONNECTED;
        break;
      case SUSPENDED:
        state = State.SUSPENDED;
        break;
      case DISCONNECTING:
        state = State.DISCONNECTING;
        break;
      case DISCONNECTED:
        state = State.DISCONNECTED;
        break;
      case UNKNOWN:
        state = State.UNKNOWN;
        break;
    }
    return state;
  }
Exemplo n.º 11
0
  @Override
  public void onReceive(Context context, Intent intent) {
    // make sure sd card is ready, if not don't try to send
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
      return;
    }

    String action = intent.getAction();
    ConnectivityManager manager =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo currentNetworkInfo = manager.getActiveNetworkInfo();

    if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
      if (currentNetworkInfo != null
          && currentNetworkInfo.getState() == NetworkInfo.State.CONNECTED) {
        if (interfaceIsEnabled(context, currentNetworkInfo)) {
          uploadForms(context);
        }
      }
    } else if (action.equals("com.geoodk.collect.android.FormSaved")) {
      ConnectivityManager connectivityManager =
          (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo ni = connectivityManager.getActiveNetworkInfo();

      if (ni == null || !ni.isConnected()) {
        // not connected, do nothing
      } else {
        if (interfaceIsEnabled(context, ni)) {
          uploadForms(context);
        }
      }
    }
  }
Exemplo n.º 12
0
 public boolean isConnectingToInternet() {
   boolean status = false;
   try {
     ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
     NetworkInfo netInfo = cm.getNetworkInfo(0);
     if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) {
       status = true;
     } else {
       netInfo = cm.getNetworkInfo(1);
       if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) status = true;
     }
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
   return status;
 }
Exemplo n.º 13
0
  public static int getNetType(Context ctx) {

    int iResult = NetTrafficBytesItem.DEV_WIFI;
    ConnectivityManager manager =
        (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    if (mobile.getState() == NetworkInfo.State.CONNECTED
        && wifi.getState() != NetworkInfo.State.CONNECTED) {
      iResult = NetTrafficBytesItem.DEV_GPRS;
    } else {
      iResult = NetTrafficBytesItem.DEV_WIFI;
    }

    return iResult;
  }
  private synchronized void onDunDialupReq() {
    ConnectivityManager connmgr;
    String response;
    String[] dnsServers;

    dnsServers = new String[2];
    connmgr = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo MobileInfo = connmgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    NetworkInfo WifiInfo = connmgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (MobileInfo == null && WifiInfo == null) {
      Log.w(TAG, "dialup request, get network info failed");
      response = "unknown";
      dunDialupRspNative(response, BLUETOOTH_IFACE_ADDR_START, dnsServers);
      return;
    }
    NetworkInfo.State MobileState = NetworkInfo.State.UNKNOWN;
    NetworkInfo.State WifiState = NetworkInfo.State.UNKNOWN;

    if (MobileInfo != null) MobileState = MobileInfo.getState();
    if (WifiInfo != null) WifiState = WifiInfo.getState();

    if (MobileState == NetworkInfo.State.CONNECTED || WifiState == NetworkInfo.State.CONNECTED) {
      NetworkInfo.State state =
          (MobileState == NetworkInfo.State.CONNECTED) ? MobileState : WifiState;
      if (DBG) log("startUsingNetworkFeature: (" + state + ")");
      response = "active";
      dnsServers[0] = SystemProperties.get("net.dns1");
      dnsServers[1] = SystemProperties.get("net.dns2");
      if (DBG) log("Network connected, DNS1=" + dnsServers[0] + ", " + "DNS2=" + dnsServers[1]);
      if (dnsServers[1].isEmpty()) {
        dnsServers[1] = "8.8.8.8";
      }
      if (DBG) log("Network connected, DNS2=" + dnsServers[1] + ", " + "DNS1=" + dnsServers[0]);
    } else if (MobileState == NetworkInfo.State.SUSPENDED
        || WifiState == NetworkInfo.State.SUSPENDED) {
      response = "busy";
    } else if (MobileState == NetworkInfo.State.DISCONNECTED
        || WifiState == NetworkInfo.State.DISCONNECTED) {
      response = "unavailable";
    } else {
      response = "unknown";
    }
    if (DBG) log("dunDialupRspNative response: (" + response + ")");
    dunDialupRspNative(response, BLUETOOTH_IFACE_ADDR_START, dnsServers);
  }
Exemplo n.º 15
0
 public boolean testReseau() {
   ConnectivityManager connectivityManager =
       (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
   NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
   if (networkInfo == null) return false;
   State networkState = networkInfo.getState();
   return networkState == State.CONNECTED;
 }
Exemplo n.º 16
0
  /**
   * 检测网络是否可用
   *
   * <p>同步方法,支持多线程
   */
  public static synchronized NetType checkNet(Context context) {
    NetType netType = NetType.TYPE_NONE;
    try {
      // 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理)
      ConnectivityManager connectivity =
          (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      if (connectivity != null) {
        // 获取网络连接管理的对象
        NetworkInfo info = connectivity.getActiveNetworkInfo();

        // 判断当前网络是否已经连接
        if (info != null && info.isConnected() && info.getState() == NetworkInfo.State.CONNECTED) {

          // 判断当前的接入点
          if (ConnectivityManager.TYPE_WIFI == info.getType()) // wifi连接
          netType = NetType.TYPE_WIFI;
          else if (ConnectivityManager.TYPE_MOBILE == info.getType()) { // 手机方式连接

            /**
             * 获取网络类型
             *
             * <p>NETWORK_TYPE_CDMA 网络类型为CDMA NETWORK_TYPE_EDGE 网络类型为EDGE NETWORK_TYPE_EVDO_0
             * 网络类型为EVDO0 NETWORK_TYPE_EVDO_A 网络类型为EVDOA NETWORK_TYPE_GPRS 网络类型为GPRS
             * NETWORK_TYPE_HSDPA 网络类型为HSDPA NETWORK_TYPE_HSPA 网络类型为HSPA NETWORK_TYPE_HSUPA
             * 网络类型为HSUPA NETWORK_TYPE_UMTS 网络类型为UMTS
             *
             * <p>在中国,联通的3G为UMTS或HSDPA,移动和联通的2G为GPRS或EGDE,电信的2G为CDMA,电信的3G为EVDO
             */
            if (TelephonyManager.NETWORK_TYPE_GPRS == info.getSubtype()
                || //
                TelephonyManager.NETWORK_TYPE_EDGE == info.getSubtype()
                || //
                TelephonyManager.NETWORK_TYPE_CDMA == info.getSubtype()) { // 2G网络

              netType = NetType.TYPE_2G;

            } else { // 3G或其它手机网络
              netType = NetType.TYPE_3G_OR_OTHERS;
            }

          } else { // 其它未知连接方式
            netType = NetType.TYPE_UNKNOWN;
          }

          LogUtils.info(
              "当前网络类型|" + netType.getDesc() + "|" + info.getType() + "|" + info.getSubtype());
        }
      }

    } catch (Throwable e) {
      LogUtils.error(e.getMessage(), e);
    }

    return netType;
  }
 public boolean isNetworkConnectionAvailable() {
   ConnectivityManager cm =
       (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo info = cm.getActiveNetworkInfo();
   if (info == null) return false;
   State network = info.getState();
   boolean isNetworkAvailable =
       (network == NetworkInfo.State.CONNECTED || network == NetworkInfo.State.CONNECTING);
   Log.d(TAG, "isNetworkAvailable: " + isNetworkAvailable);
   return isNetworkAvailable;
 }
 public static boolean isConnected() {
   try {
     NetworkInfo netInfo = getConnectivityManager().getActiveNetworkInfo();
     if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) {
       return true;
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return false;
 }
Exemplo n.º 19
0
  @Override
  public void onReceive(final Context context, Intent intent) {
    // When the Network connection changes, check if we're connected
    Bundle extras = intent.getExtras();
    NetworkInfo info = extras.getParcelable("networkInfo");
    NetworkInfo.State state = info.getState();
    Log.d("NetworkReceiver", info.toString() + " " + state.toString());

    // If so, upload
    if (state == NetworkInfo.State.CONNECTED) {
      new RemoteDatabaseHelper(context).checkConnectionAndUpload();
    }
  }
Exemplo n.º 20
0
  public boolean checkNetEnv() {
    ConnectivityManager conMan =
        (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo.State mobile = null;
    NetworkInfo.State wifi = null;
    NetworkInfo mobileInfo = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mobileInfo != null) {
      mobile = mobileInfo.getState();
    }
    NetworkInfo wifiInfo = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiInfo != null) {
      wifi = wifiInfo.getState();
    }
    if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) {
      return true;
    }
    if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
      return true;
    }
    return false;
  }
Exemplo n.º 21
0
  /**
   * This method is use to check the device internet connectivity.
   *
   * @param context
   * @return true :if your device is connected to internet. false :if your device is not connected
   *     to internet.
   */
  public static boolean isConnected(Context context) {
    // return true;
    // TODO un-comment when prototype demo done.

    ConnectivityManager manager =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();

    if (info == null) return false;
    if (info.getState() != State.CONNECTED) return false;

    return true;
  }
 public static boolean isNetWorkAvailable(Context context) {
   boolean isAvailable = false;
   ConnectivityManager connectivityManager =
       (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
   if (connectivityManager != null) {
     NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
     if (networkInfo != null) {
       DetailedState detailedState = networkInfo.getDetailedState();
       String detailedName = detailedState.name();
       if (detailedName == null) {
         detailedName = "";
       }
       networkTable.put("detailedName", detailedName);
       String extraInfo = networkInfo.getExtraInfo();
       if (extraInfo == null) {
         extraInfo = "";
       }
       networkTable.put("extraInfo", extraInfo);
       String reason = networkInfo.getReason();
       if (reason == null) {
         reason = "";
       }
       networkTable.put("reason", reason);
       NetworkInfo.State state = networkInfo.getState();
       String stateName = "";
       if (state != null && state.name() != null) {
         stateName = state.name();
       }
       // 经过多次测试,只有stateName可以准确的判断网络连接是否正常
       if ("CONNECTED".equalsIgnoreCase(stateName)) {
         isAvailable = true;
       }
       networkTable.put("stateName", stateName);
       int subType = networkInfo.getSubtype();
       networkTable.put("subType", subType + "");
       String subtypeName = networkInfo.getSubtypeName();
       if (subtypeName == null) {
         subtypeName = "";
       }
       networkTable.put("subtypeName", subtypeName);
       //				int type = networkInfo.getType();
       String typeName = networkInfo.getTypeName();
       if (typeName == null) {
         typeName = "";
       }
       networkTable.put("typeName", typeName);
       Log.d(LOG_TAG, getLogString());
     }
   }
   return isAvailable;
 }
Exemplo n.º 23
0
 private boolean isMMSNotTransaction() {
   boolean isMMSNotProcess = true;
   ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
   if (cm != null) {
     NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_MMS);
     if (networkInfo != null) {
       NetworkInfo.State state = networkInfo.getState();
       Xlog.d(TAG, "mms state = " + state);
       isMMSNotProcess =
           (state != NetworkInfo.State.CONNECTING && state != NetworkInfo.State.CONNECTED);
     }
   }
   return isMMSNotProcess;
 }
  /* When there's no active Internet connection ServiceManager is being
   * notified about that in order to turn off updates. In the other case it
   * receives message that phone is connected to active network and service
   * should start to update cities data. */
  private void controlServiceManager(Context context) {
    State networkInfoMobileState = networkInfoMobile.getState();
    // networkInfoMobileState == DISCONNECTED	=> Not connected
    // networkInfoMobileState == UNKNOWN		=> No SIM card

    // when device is off-line:
    if ((networkInfoMobileState.equals(NetworkInfo.State.DISCONNECTED)
            || networkInfoMobileState.equals(NetworkInfo.State.UNKNOWN))
        && networkInfoWifi.getState().equals(NetworkInfo.State.DISCONNECTED)) {
      Log.d(LOG_TAG, context.getResources().getString(R.string.alert_internet_connection_title));

      context.stopService(new Intent(context, ServiceManager.class));
      isServiceManagerRunning = false;
    }
    /* device is online but it has to be checked if:
     * WIFI and MOBILE had been both online but only one of them was turned off
     * so in that case there is no need to start ServiceManager one again
     */
    else if (!isServiceManagerRunning) {
      context.startService(new Intent(context, ServiceManager.class));
      isServiceManagerRunning = true;
    }
  }
Exemplo n.º 25
0
 @Override
 public void onReceive(Context context, Intent intent) {
   lastSyncFromNetworkChange = Preferences.getLong(PREF_LAST_SYNC_FROM_NETWORK_CHANGE, 0L);
   if (DateUtilities.now() - lastSyncFromNetworkChange > DateUtilities.ONE_MINUTE * 10) {
     NetworkInfo info = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
     if (info != null
         && NetworkInfo.State.CONNECTED.equals(info.getState())
         && PluginServices.getActFmPreferenceService().isLoggedIn()) {
       ActFmSyncThread syncThread = ActFmSyncThread.getInstance();
       syncThread.repopulateQueueFromOutstandingTables();
       Preferences.setLong(PREF_LAST_SYNC_FROM_NETWORK_CHANGE, DateUtilities.now());
     }
   }
 }
Exemplo n.º 26
0
 /** 获取默认 */
 protected boolean getNetWorkStatus() {
   boolean result = false;
   ConnectivityManager cm =
       (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo netinfo = cm.getActiveNetworkInfo();
   if (netinfo != null && netinfo.isConnected()) {
     if (netinfo.getState() == NetworkInfo.State.CONNECTED) {
       result = true;
     } else {
       result = false;
     }
   }
   return result;
 }
Exemplo n.º 27
0
 @SuppressWarnings("static-access")
 public static Boolean HasInternet(Context myContext) {
   Boolean HasConnection = false;
   ConnectivityManager connectivityManager =
       (ConnectivityManager) myContext.getSystemService(myContext.CONNECTIVITY_SERVICE);
   NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
   if (activeNetworkInfo != null) {
     State myState = activeNetworkInfo.getState();
     if (myState == State.CONNECTED || myState == State.CONNECTING) {
       HasConnection = true;
     }
   }
   return HasConnection;
 }
Exemplo n.º 28
0
  /**
   * Auther:张宇辉 User:zhangyuhui 2015年1月5日 上午9:58:37 Project_Name:DFram Description:TODO(判断网络是否连接)
   * Throws boolean
   */
  public static boolean isConnected(Context context) {
    ConnectivityManager connectivity =
        (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    if (null != connectivity) {

      NetworkInfo info = connectivity.getActiveNetworkInfo();
      if (null != info && info.isConnected()) {
        if (info.getState() == NetworkInfo.State.CONNECTED) {
          return true;
        }
      }
    }
    return false;
  }
Exemplo n.º 29
0
  public static String[] getNetworkState(Context var0) {
    String[] var1 = new String[] {"Unknown", "Unknown"};

    try {
      PackageManager var2 = var0.getPackageManager();
      if (var2.checkPermission("android.permission.ACCESS_NETWORK_STATE", var0.getPackageName())
          != 0) {
        var1[0] = "Unknown";
        return var1;
      }

      ConnectivityManager var3 =
          (ConnectivityManager) var0.getSystemService(Context.CONNECTIVITY_SERVICE);
      if (var3 == null) {
        var1[0] = "Unknown";
        return var1;
      }

      NetworkInfo var4 = var3.getNetworkInfo(1);
      if (var4.getState() == NetworkInfo.State.CONNECTED) {
        var1[0] = "Wi-Fi";
        return var1;
      }

      NetworkInfo var5 = var3.getNetworkInfo(0);
      if (var5.getState() == NetworkInfo.State.CONNECTED) {
        var1[0] = "2G/3G";
        var1[1] = var5.getSubtypeName();
        return var1;
      }
    } catch (Exception var6) {
      var6.printStackTrace();
    }

    return var1;
  }
Exemplo n.º 30
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;
 }