當前位置: 首頁>>代碼示例>>Java>>正文


Java NetworkInfo.isConnected方法代碼示例

本文整理匯總了Java中android.net.NetworkInfo.isConnected方法的典型用法代碼示例。如果您正苦於以下問題:Java NetworkInfo.isConnected方法的具體用法?Java NetworkInfo.isConnected怎麽用?Java NetworkInfo.isConnected使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.net.NetworkInfo的用法示例。


在下文中一共展示了NetworkInfo.isConnected方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getNetworkTypeName

import android.net.NetworkInfo; //導入方法依賴的package包/類
public static String getNetworkTypeName(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo;
    String type = NETWORK_TYPE_DISCONNECT;
    if (manager == null || (networkInfo = manager.getActiveNetworkInfo()) == null) {
        return type;
    }

    if (networkInfo.isConnected()) {
        String typeName = networkInfo.getTypeName();
        if ("WIFI".equalsIgnoreCase(typeName)) {
            type = NETWORK_TYPE_WIFI;
        } else if ("MOBILE".equalsIgnoreCase(typeName)) {
            String proxyHost = android.net.Proxy.getDefaultHost();
            type = TextUtils.isEmpty(proxyHost) ? (isFastMobileNetwork(context) ? NETWORK_TYPE_3G : NETWORK_TYPE_2G)
                    : NETWORK_TYPE_WAP;
        } else {
            type = NETWORK_TYPE_UNKNOWN;
        }
    }
    return type;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:Kits.java

示例2: isNetworkAvailable

import android.net.NetworkInfo; //導入方法依賴的package包/類
public static boolean isNetworkAvailable() {
    try {
        ConnectivityManager connectivity = (ConnectivityManager) AppManager.app().getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) {
            NetworkInfo info = connectivity.getActiveNetworkInfo();
            if (info != null && info.isConnected()) {
                if (info.getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return false;
}
 
開發者ID:nowandfurure,項目名稱:richeditor,代碼行數:18,代碼來源:Utils.java

示例3: getNetWorkType

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * get the network type (wifi,wap,2g,3g)
 *
 * @param context
 * @return
 */
public static int getNetWorkType(Context context) {

    int mNetWorkType = NETWORKTYPE_INVALID;
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        String type = networkInfo.getTypeName();
        if (type.equalsIgnoreCase("WIFI")) {
            mNetWorkType = NETWORKTYPE_WIFI;
        } else if (type.equalsIgnoreCase("MOBILE")) {
            String proxyHost = android.net.Proxy.getDefaultHost();
            mNetWorkType = TextUtils.isEmpty(proxyHost)
                    ? (isFastMobileNetwork(context) ? NETWORKTYPE_3G : NETWORKTYPE_2G)
                    : NETWORKTYPE_WAP;
        }
    } else {
        mNetWorkType = NETWORKTYPE_INVALID;
    }
    return mNetWorkType;
}
 
開發者ID:BlueYangDroid,項目名稱:MvpPlus,代碼行數:27,代碼來源:LoaderConfig.java

示例4: isConnectingToInternet

import android.net.NetworkInfo; //導入方法依賴的package包/類
public boolean isConnectingToInternet(){
    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;
                  }

          NetworkInfo mWifi = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

          if (mWifi.isConnected()) {

              return true;
          }
 
      }
      return false;
}
 
開發者ID:SkylineLabs,項目名稱:FindX,代碼行數:23,代碼來源:ConnectionDetector.java

示例5: isNetworkConnected

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * 判斷網絡是否連通
 */
public static boolean isNetworkConnected(Context context) {
    try {
        if(context!=null){
            @SuppressWarnings("static-access")
            ConnectivityManager cm = (ConnectivityManager) context
                    .getSystemService(context.CONNECTIVITY_SERVICE);
            NetworkInfo info = cm.getActiveNetworkInfo();
            return info != null && info.isConnected();
        }else{
            /**如果context為空,就返回false,表示網絡未連接*/
            return false;
        }
    }catch (Exception e){
        e.printStackTrace();
        return false;
    }


}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:CheckNetwork.java

示例6: netIsConnected

import android.net.NetworkInfo; //導入方法依賴的package包/類
public static boolean netIsConnected(Context context) {
    ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    //手機網絡連接狀態
    NetworkInfo mobNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    //WIFI連接狀態
    NetworkInfo wifiNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (!mobNetInfo.isConnected() && !wifiNetInfo.isConnected()) {
        //當前無可用的網絡
        return false;
    }
    return true;
}
 
開發者ID:yangxp108,項目名稱:MVPArms_Fragment-fragment,代碼行數:13,代碼來源:DeviceUtils.java

示例7: isNetworkAvailable

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * Determina se internet è attivo
 */
public static boolean isNetworkAvailable(Context c) {
    ConnectivityManager connectivityManager
            = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
 
開發者ID:IelloDevTeam,項目名稱:IelloAndroidApp,代碼行數:10,代碼來源:HelperRete.java

示例8: check3Gwifi

import android.net.NetworkInfo; //導入方法依賴的package包/類
public static boolean check3Gwifi(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo infoM = manager.getNetworkInfo(0);
    if (manager.getNetworkInfo(1).isConnected() || infoM.isConnected()) {
        return true;
    }
    return false;
}
 
開發者ID:JamesLiAndroid,項目名稱:AndroidKillerService,代碼行數:9,代碼來源:OtherOperatorService.java

示例9: getConnectionInfo

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * Get the latest network connection information
 *
 * @param info the current active network info
 * @return a JSONObject that represents the network info
 */
private JSONObject getConnectionInfo(NetworkInfo info) {
    String type = TYPE_NONE;
    String extraInfo = "";
    if (info != null) {
        // If we are not connected to any network set type to none
        if (!info.isConnected()) {
            type = TYPE_NONE;
        }
        else {
            type = getType(info);
        }
        extraInfo = info.getExtraInfo();
    }

    LOG.d(LOG_TAG, "Connection Type: " + type);
    LOG.d(LOG_TAG, "Connection Extra Info: " + extraInfo);

    JSONObject connectionInfo = new JSONObject();

    try {
        connectionInfo.put("type", type);
        connectionInfo.put("extraInfo", extraInfo);
    } catch (JSONException e) {
        LOG.d(LOG_TAG, e.getLocalizedMessage());
    }

    return connectionInfo;
}
 
開發者ID:SUTFutureCoder,項目名稱:localcloud_fe,代碼行數:35,代碼來源:NetworkManager.java

示例10: isDeviceOnline

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * Checks whether the device currently has a network connection.
 *
 * @return true if the device has a network connection, false otherwise.
 */
private boolean isDeviceOnline() {
    ConnectivityManager connMgr =
            (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    return (networkInfo != null && networkInfo.isConnected());
}
 
開發者ID:webianks,項目名稱:Crimson,代碼行數:12,代碼來源:CheckupReminders.java

示例11: isOnline

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * @return true if the internet connection currently in use is functional,
 * otherwise false
 */
public static boolean isOnline(final Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(
            Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnected();
}
 
開發者ID:wahibhaq,項目名稱:urdu-font-comparator-app,代碼行數:11,代碼來源:Utils.java

示例12: isConnected

import android.net.NetworkInfo; //導入方法依賴的package包/類
public boolean isConnected(Context context){
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Activity.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected())
        return true;
    else
        return false;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:CheckNetwork.java

示例13: isNetWorkConnected

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * check if network avalable
 * 
 * @param context
 * @return
 */
public static boolean isNetWorkConnected(Context context) {
	if (context != null) {
		ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
		if (mNetworkInfo != null) {
			return mNetworkInfo.isAvailable() && mNetworkInfo.isConnected();
		}
	}

	return false;
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:18,代碼來源:EaseCommonUtils.java

示例14: networkIsConnected

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * Get the state of networking connection of the current mobile
 * @return the network is connected in mobile or not
 */
public static boolean networkIsConnected(Context context){
    ConnectivityManager connectivityManager =
            (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo =
            connectivityManager.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected();
}
 
開發者ID:MohamedNagyMostafa,項目名稱:IM_Here,代碼行數:12,代碼來源:Utility.java

示例15: isDeviceOnline

import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
 * Check internet connectivity.
 *
 * @return true if device is connect to <b>any</b> network, false otherwise.
 */
private boolean isDeviceOnline(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return info != null && info.isConnected();
}
 
開發者ID:allaudin,項目名稱:ease-volley-wrapper,代碼行數:11,代碼來源:EaseRequest.java


注:本文中的android.net.NetworkInfo.isConnected方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。