当前位置: 首页>>代码示例>>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;未经允许,请勿转载。