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


Java State類代碼示例

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


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

示例1: ConnectivityReceiver

import android.net.NetworkInfo.State; //導入依賴的package包/類
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,代碼行數:21,代碼來源:ConnectivityReceiver.java

示例2: onReceive

import android.net.NetworkInfo.State; //導入依賴的package包/類
@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,代碼行數:27,代碼來源:ConnectivityReceiver.java

示例3: getNetworkAccessMode

import android.net.NetworkInfo.State; //導入依賴的package包/類
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,代碼行數:26,代碼來源:DeviceConfig.java

示例4: j

import android.net.NetworkInfo.State; //導入依賴的package包/類
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,代碼行數:28,代碼來源:bt.java

示例5: updateState

import android.net.NetworkInfo.State; //導入依賴的package包/類
void updateState(State state) {
	
	if (state != State.DISCONNECTED) {
		mTryCounter = 0;
	}
	
	Setting s = mSetting; int resId;
	switch (state) {
		case CONNECTED: s.checked = true; s.enabled = true; resId = R.string.txt_net_status_connected; break;
		case CONNECTING: s.checked = false; s.enabled = false; resId = R.string.txt_net_status_connecting; break;
		case DISCONNECTED: s.checked = false; s.enabled = true; resId = R.string.txt_net_status_disconnected; break;
		case DISCONNECTING: s.checked = true; s.enabled = false; resId = R.string.txt_net_status_disconnecting; break;
		default: s.checked = s.enabled = false; resId = R.string.txt_status_unknown; break;
	}
	s.descr = getString(resId);
	s.updateView();
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:18,代碼來源:MobileDataSettingHandler2.java

示例6: getNetworkState

import android.net.NetworkInfo.State; //導入依賴的package包/類
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,代碼行數:20,代碼來源:NetWorkUtil.java

示例7: k

import android.net.NetworkInfo.State; //導入依賴的package包/類
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,代碼行數:28,代碼來源:bt.java

示例8: a

import android.net.NetworkInfo.State; //導入依賴的package包/類
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,代碼行數:23,代碼來源:k.java

示例9: isNetworkAvailable

import android.net.NetworkInfo.State; //導入依賴的package包/類
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,代碼行數:15,代碼來源:HttpUtils.java

示例10: isWifiEnabled

import android.net.NetworkInfo.State; //導入依賴的package包/類
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,代碼行數:8,代碼來源:Util.java

示例11: getNetworkType

import android.net.NetworkInfo.State; //導入依賴的package包/類
/**
 * 獲取網絡連接狀態
 */
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,代碼行數:36,代碼來源:NetWorkHelper.java

示例12: checkNet

import android.net.NetworkInfo.State; //導入依賴的package包/類
/**
 * 判斷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,代碼行數:24,代碼來源:DeviceUtil.java

示例13: getCurrentNetType

import android.net.NetworkInfo.State; //導入依賴的package包/類
/**
 * 獲取當前網絡狀態的類型
 * @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,代碼行數:22,代碼來源:NetWorkUtil.java

示例14: isConnected

import android.net.NetworkInfo.State; //導入依賴的package包/類
/**
 * 判斷網絡是否連接
 *
 * @param
 * @return
 */
public static boolean isConnected() {

    ConnectivityManager connectivity = (ConnectivityManager) mContext
            .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;
}
 
開發者ID:yinfork,項目名稱:InfoQ-Android-App,代碼行數:24,代碼來源:NetWorkUtil.java

示例15: getNetworkState

import android.net.NetworkInfo.State; //導入依賴的package包/類
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.,代碼行數:20,代碼來源:NetUtil.java


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