当前位置: 首页>>代码示例>>Java>>正文


Java State.CONNECTED属性代码示例

本文整理汇总了Java中android.net.NetworkInfo.State.CONNECTED属性的典型用法代码示例。如果您正苦于以下问题:Java State.CONNECTED属性的具体用法?Java State.CONNECTED怎么用?Java State.CONNECTED使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.net.NetworkInfo.State的用法示例。


在下文中一共展示了State.CONNECTED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ConnectivityReceiver

public ConnectivityReceiver(TerminalManager manager, boolean lockingWifi) {
	mTerminalManager = manager;

	final ConnectivityManager cm =
			(ConnectivityManager) manager.getSystemService(Context.CONNECTIVITY_SERVICE);

	final WifiManager wm = (WifiManager) manager.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
	mWifiLock = wm.createWifiLock(TAG);

	final NetworkInfo info = cm.getActiveNetworkInfo();
	if (info != null) {
		mIsConnected = (info.getState() == State.CONNECTED);
	}

	mLockingWifi = lockingWifi;

	final IntentFilter filter = new IntentFilter();
	filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
	manager.registerReceiver(this, filter);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:ConnectivityReceiver.java

示例2: onReceive

@Override
public void onReceive(Context context, Intent intent) {
	final String action = intent.getAction();

	if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
		Log.w(TAG, "onReceived() called: " + intent);
		return;
	}

	boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
	boolean isFailover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);

	Log.d(TAG, "onReceived() called; noConnectivity? " + noConnectivity + "; isFailover? " + isFailover);

	if (noConnectivity && !isFailover && mIsConnected) {
		mIsConnected = false;
		mTerminalManager.onConnectivityLost();
	} else if (!mIsConnected) {
		NetworkInfo info = (NetworkInfo) intent.getExtras()
				.get(ConnectivityManager.EXTRA_NETWORK_INFO);

		if (mIsConnected = (info.getState() == State.CONNECTED)) {
			mTerminalManager.onConnectivityRestored();
		}
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ConnectivityReceiver.java

示例3: getNetworkAccessMode

public static String[] getNetworkAccessMode(Context context) {
    String[] strArr = new String[]{UNKNOW, UNKNOW};
    if (context.getPackageManager().checkPermission("android.permission" +
            ".ACCESS_NETWORK_STATE", context.getPackageName()) != 0) {
        strArr[0] = UNKNOW;
        return strArr;
    }
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService
            ("connectivity");
    if (connectivityManager == null) {
        strArr[0] = UNKNOW;
        return strArr;
    } else if (connectivityManager.getNetworkInfo(1).getState() == State.CONNECTED) {
        strArr[0] = "Wi-Fi";
        return strArr;
    } else {
        NetworkInfo networkInfo = connectivityManager.getNetworkInfo(0);
        if (networkInfo.getState() != State.CONNECTED) {
            return strArr;
        }
        strArr[0] = "2G/3G";
        strArr[1] = networkInfo.getSubtypeName();
        return strArr;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:25,代码来源:DeviceConfig.java

示例4: j

public static String[] j(Context context) {
    String[] strArr = new String[]{"", ""};
    try {
        if (context.getPackageManager().checkPermission("android.permission.ACCESS_NETWORK_STATE", context.getPackageName()) != 0) {
            strArr[0] = "";
            return strArr;
        }
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
        if (connectivityManager == null) {
            strArr[0] = "";
            return strArr;
        } else if (connectivityManager.getNetworkInfo(1).getState() == State.CONNECTED) {
            strArr[0] = d;
            return strArr;
        } else {
            NetworkInfo networkInfo = connectivityManager.getNetworkInfo(0);
            if (networkInfo.getState() == State.CONNECTED) {
                strArr[0] = c;
                strArr[1] = networkInfo.getSubtypeName();
                return strArr;
            }
            return strArr;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:27,代码来源:bt.java

示例5: getNetworkState

public static int getNetworkState(Context context) {
	ConnectivityManager connManager = (ConnectivityManager) context
			.getSystemService(Context.CONNECTIVITY_SERVICE);

	// Wifi
	State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
			.getState();
	if (state == State.CONNECTED || state == State.CONNECTING) {
		return STATE_WIFI;
	}

	// 3G
	state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
			.getState();
	if (state == State.CONNECTED || state == State.CONNECTING) {
		return STATE_MOBILE;
	}
	return STATE_DISCONNECT;
}
 
开发者ID:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:19,代码来源:NetWorkUtil.java

示例6: k

public static String[] k(Context context) {
    String[] strArr = new String[]{"", ""};
    try {
        if (a(context, "android.permission.ACCESS_NETWORK_STATE")) {
            ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
            if (connectivityManager == null) {
                strArr[0] = "";
                return strArr;
            } else if (connectivityManager.getNetworkInfo(1).getState() == State.CONNECTED) {
                strArr[0] = d;
                return strArr;
            } else {
                NetworkInfo networkInfo = connectivityManager.getNetworkInfo(0);
                if (networkInfo.getState() == State.CONNECTED) {
                    strArr[0] = c;
                    strArr[1] = networkInfo.getSubtypeName();
                    return strArr;
                }
                return strArr;
            }
        }
        strArr[0] = "";
        return strArr;
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:27,代码来源:bt.java

示例7: a

public static boolean a(Context context) {
    if (!o.a(context, "android.permission.INTERNET")) {
        return false;
    }
    if (context != null) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService("connectivity");
        if (connectivityManager == null) {
            return false;
        }
        Object allNetworkInfo = connectivityManager.getAllNetworkInfo();
        if (l.b(allNetworkInfo)) {
            for (NetworkInfo state : allNetworkInfo) {
                if (state.getState() == State.CONNECTED) {
                    return true;
                }
            }
        }
    }
    Toast.makeText(context, "Unable to connect to the network.", 0).show();
    return false;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:22,代码来源:k.java

示例8: isNetworkAvailable

public static boolean isNetworkAvailable(Context context) {
    if (context != null) {
        NetworkInfo[] info = ((ConnectivityManager) context.getSystemService("connectivity"))
                .getAllNetworkInfo();
        if (info != null) {
            for (NetworkInfo state : info) {
                if (state.getState() == State.CONNECTED) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:14,代码来源:HttpUtils.java

示例9: isWifiEnabled

public static boolean isWifiEnabled(Context context) {
    ConnectivityManager mgrConn = (ConnectivityManager) context.getSystemService
            ("connectivity");
    return (mgrConn.getActiveNetworkInfo() != null && mgrConn.getActiveNetworkInfo().getState
            () == State.CONNECTED) || ((TelephonyManager) context.getSystemService("phone"))
            .getNetworkType() == 3;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:7,代码来源:Util.java

示例10: getNetworkType

/**
 * 获取网络连接状态
 */
public static int getNetworkType(Context context) {
    // NetworkInfo 有以下方法
    // getDetailedState():获取详细状态。
    // getExtraInfo():获取附加信息(3gnet/3gwap/uninet/uniwap/cmnet/cmwap/ctnet/ctwap)
    // getReason():获取连接失败的原因。
    // getType():获取网络类型(一般为移动或Wi-Fi)。
    // getTypeName():获取网络类型名称(一般取值“WIFI”或“MOBILE”)。
    // isAvailable():判断该网络是否可用。
    // isConnected():判断是否已经连接。
    // isConnectedOrConnecting():判断是否已经连接或正在连接。
    // isFailover():判断是否连接失败。
    // isRoaming():判断是否漫游

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

    NetworkInfo networkInfo = connectivity.getActiveNetworkInfo();
    if (networkInfo != null) {
        int type = networkInfo.getType();
        State state = networkInfo.getState();

        if (type == ConnectivityManager.TYPE_WIFI
                && state == State.CONNECTED) {
            // wifi连接通畅
            return NETWORK_CONNETED_WIFI;
        } else if (type == ConnectivityManager.TYPE_MOBILE
                && state == State.CONNECTED) {
            return NETWORK_CONNETED_GPRS;
        }
    }
    return NETWORK_DISCONNETED;
}
 
开发者ID:FacePlusPlus,项目名称:MegviiLicMgr-Android-SDK,代码行数:35,代码来源:NetWorkHelper.java

示例11: checkNet

/**
 * 判断Android客户端网络是否连接
 * 只能判断是否有可用的连接,而不能判断是否能连网
 *
 * @param context
 * @return true/false
 */
public static boolean checkNet(Context context) {
    try {
        ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) {
            NetworkInfo info = connectivity.getActiveNetworkInfo();
            if (info != null && info.isConnected()) {
                if (info.getState() == State.CONNECTED) {
                    return true;
                }
            }
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}
 
开发者ID:hljwang3874149,项目名称:ElephantReader,代码行数:23,代码来源:DeviceUtil.java

示例12: getCurrentNetType

/**
 * 获取当前网络状态的类型
 * @return 返回网络类型
 */
public NetType getCurrentNetType() {
    ConnectivityManager connManager = (ConnectivityManager) mContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); // wifi
    NetworkInfo gprs = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); // gprs

    if (wifi != null && wifi.getState() == State.CONNECTED) {
         Log.d(TAG, "getCurrentNetType | Current net type:  WIFI.");
        return NetType.NETWORK_TYPE_WIFI;
    } else if (gprs != null && gprs.getState() == State.CONNECTED) {
         Log.d(TAG, "getCurrentNetType | Current net type:  MOBILE.");
        return NetType.NETWOKR_TYPE_MOBILE;
    } else {
         Log.d(TAG, "getCurrentNetType | Current net type:  NONE.");
        return NetType.NETWORK_TYPE_NONE;
    }
}
 
开发者ID:yinfork,项目名称:InfoQ-Android-App,代码行数:21,代码来源:NetWorkUtil.java

示例13: getNetworkState

public static int getNetworkState(Context context) {
	ConnectivityManager connManager = (ConnectivityManager) context
			.getSystemService(Context.CONNECTIVITY_SERVICE);

	// Wifi
	State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
			.getState();
	if (state == State.CONNECTED || state == State.CONNECTING) {
		return NETWORN_WIFI;
	}

	// 3G
	state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
			.getState();
	if (state == State.CONNECTED || state == State.CONNECTING) {
		return NETWORN_MOBILE;
	}
	return NETWORN_NONE;
}
 
开发者ID:cckevincyh,项目名称:C.,代码行数:19,代码来源:NetUtil.java

示例14: checkNetworkEnable

/***
 * 检查网络
 *
 * @param context Context
 * @param toast   是否需要toast提示
 * @return true or false
 */
public static boolean checkNetworkEnable(Context context, boolean toast) {
    if (context == null) {
        return false;
    }
    ConnectivityManager manager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();
    if (info != null && info.isConnected()
            && info.getState() == State.CONNECTED) {
        return true;
    }
    if (toast) {
        ZToastUtils.toastNoNetWork(context);
    }
    return false;
}
 
开发者ID:BigAppOS,项目名称:BigApp_WordPress_Android,代码行数:23,代码来源:CommonUtils.java

示例15: getNetworkType

/**
 * @param context Context
 * @return 1-wifi, 2-3G, 0-无网络连接
 */
public static int getNetworkType(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    State mobileState = connectivityManager.getNetworkInfo(
            ConnectivityManager.TYPE_MOBILE).getState();
    State wifiState = connectivityManager.getNetworkInfo(
            ConnectivityManager.TYPE_WIFI).getState();
    if (wifiState == State.CONNECTED || wifiState == State.CONNECTING) {
        return 1;
    } else if (mobileState == State.CONNECTED
            || mobileState == State.CONNECTING) {
        return 2;
    } else {
        return 0;
    }
}
 
开发者ID:BigAppOS,项目名称:BigApp_WordPress_Android,代码行数:20,代码来源:CommonUtils.java


注:本文中的android.net.NetworkInfo.State.CONNECTED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。