WEB开发网
开发学院手机开发Android 开发 Android: 判断网络连接状态及连接类型 阅读

Android: 判断网络连接状态及连接类型

 2012-06-04 16:56:06 来源:WEB开发网   
核心提示: // Checks the network connection and sets the wifiConnected and mobileConnected // variables accordingly. private void updateConnectedFlags() {
    // Checks the network connection and sets the wifiConnected and mobileConnected
    // variables accordingly.
    private void updateConnectedFlags() {
        ConnectivityManager connMgr =
                (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
        if (activeInfo != null && activeInfo.isConnected()) {
            wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
            mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
        } else {
            wifiConnected = false;
            mobileConnected = false;
        }
    }

Tags:Android 判断 网络

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接