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


Java WifiManager.WIFI_STATE_UNKNOWN屬性代碼示例

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


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

示例1: onHandleIntent

@Override
protected void onHandleIntent(Intent intent) {
    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_LOWEST);
    if (intent == null) {
        Utils.debugLog(TAG, "received null Intent, ignoring");
        return;
    }
    Utils.debugLog(TAG, "WiFi change service started, clearing info about wifi state until we have figured it out again.");
    NetworkInfo ni = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
    wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
    int wifiState = wifiManager.getWifiState();
    if (ni == null || ni.isConnected()) {
        Utils.debugLog(TAG, "ni == " + ni + "  wifiState == " + printWifiState(wifiState));
        if (wifiState == WifiManager.WIFI_STATE_ENABLED
                || wifiState == WifiManager.WIFI_STATE_DISABLING  // might be switching to hotspot
                || wifiState == WifiManager.WIFI_STATE_DISABLED   // might be hotspot
                || wifiState == WifiManager.WIFI_STATE_UNKNOWN) { // might be hotspot
            if (wifiInfoThread != null) {
                wifiInfoThread.interrupt();
            }
            wifiInfoThread = new WifiInfoThread();
            wifiInfoThread.start();
        }
    }
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:25,代碼來源:WifiStateChangeService.java

示例2: onReceive

@Override
public void onReceive(Context c, Intent intent) {
	Bundle bundle = intent.getExtras();
	int statusInt = bundle.getInt("wifi_state");
	switch (statusInt) {
	case WifiManager.WIFI_STATE_UNKNOWN:
		break;
	case WifiManager.WIFI_STATE_ENABLING:
		break;
	case WifiManager.WIFI_STATE_ENABLED:
		LogUtil.e(TAG, "wifi enable");
		startThread();
		break;
	case WifiManager.WIFI_STATE_DISABLING:
		break;
	case WifiManager.WIFI_STATE_DISABLED:
		LogUtil.e(TAG, "wifi disabled");
		break;
	default:
		break;
	}
}
 
開發者ID:leobert-lan,項目名稱:UiLib,代碼行數:22,代碼來源:DLNAService.java

示例3: printWifiState

private String printWifiState(int wifiState) {
    switch (wifiState) {
        case WifiManager.WIFI_STATE_DISABLED:
            return "WIFI_STATE_DISABLED";
        case WifiManager.WIFI_STATE_DISABLING:
            return "WIFI_STATE_DISABLING";
        case WifiManager.WIFI_STATE_ENABLING:
            return "WIFI_STATE_ENABLING";
        case WifiManager.WIFI_STATE_ENABLED:
            return "WIFI_STATE_ENABLED";
        case WifiManager.WIFI_STATE_UNKNOWN:
            return "WIFI_STATE_UNKNOWN";
    }
    return null;
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:15,代碼來源:WifiStateChangeService.java

示例4: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    // 這個監聽wifi的打開與關閉,與wifi的連接無關
    if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {
        int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
        Log.e(TAG, "wifiState" + wifiState);
        switch (wifiState) {
            case WifiManager.WIFI_STATE_DISABLED:
                Log.d(TAG, "onReceive: WIFI_STATE_DISABLED");
                break;
            case WifiManager.WIFI_STATE_DISABLING:
                break;
            case WifiManager.WIFI_STATE_ENABLING:
                break;
            case WifiManager.WIFI_STATE_ENABLED:
                Log.d(TAG, "onReceive: WIFI_STATE_ENABLED");
                break;
            case WifiManager.WIFI_STATE_UNKNOWN:
                break;
            default:
                break;
        }
    }

    // 這個監聽wifi的連接狀態即是否連上了一個有效無線路由,當上邊廣播的狀態是WifiManager
    // .WIFI_STATE_DISABLING,和WIFI_STATE_DISABLED的時候,根本不會接到這個廣播。
    // 在上邊廣播接到廣播是WifiManager.WIFI_STATE_ENABLED狀態的同時也會接到這個廣播,
    // 當然剛打開wifi肯定還沒有連接到有效的無線
    if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
        Parcelable parcelableExtra = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        if (null != parcelableExtra) {
            NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;
            NetworkInfo.State state = networkInfo.getState();
            boolean isConnected = state == State.CONNECTED;// 當然,這邊可以更精確的確定狀態
            Log.e(TAG, "isConnected" + isConnected);
            if (isConnected) {
            } else {
            }
        }
    }

    // 這個監聽網絡連接的設置,包括wifi和移動數據的打開和關閉。.
    // 最好用的還是這個監聽。wifi如果打開,關閉,以及連接上可用的連接都會接到監聽。見log
    // 這個廣播的最大弊端是比上邊兩個廣播的反應要慢,如果隻是要監聽wifi,我覺得還是用上邊兩個配合比較合適
    if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
        ConnectivityManager manager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        Log.i(TAG, "CONNECTIVITY_ACTION");

        NetworkInfo activeNetwork = manager.getActiveNetworkInfo();
        if (activeNetwork != null) { // connected to the internet
            if (activeNetwork.isConnected()) {
                if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
                    // connected to wifi
                    Log.e(TAG, "當前WiFi連接可用 ");
                } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
                    // connected to the mobile provider's data plan
                    Log.e(TAG, "當前移動網絡連接可用 ");
                }
            } else {
                Log.e(TAG, "當前沒有網絡連接,請確保你已經打開網絡 ");
            }


            Log.e(TAG, "info.getTypeName()" + activeNetwork.getTypeName());
            Log.e(TAG, "getSubtypeName()" + activeNetwork.getSubtypeName());
            Log.e(TAG, "getState()" + activeNetwork.getState());
            Log.e(TAG, "getDetailedState()"+ activeNetwork.getDetailedState().name());
            Log.e(TAG, "getDetailedState()" + activeNetwork.getExtraInfo());
            Log.e(TAG, "getType()" + activeNetwork.getType());
        } else {   // not connected to the internet
            Log.e(TAG, "當前沒有網絡連接,請確保你已經打開網絡 ");
        }
    }
}
 
開發者ID:fendoudebb,項目名稱:PlayAndroid,代碼行數:75,代碼來源:NetworkChangeReceiver.java

示例5: wifiStateChangedAction

/**
 * 
 * @param context
 * @param intent
 * @param action
 */
public static void wifiStateChangedAction(Context context, Intent intent, String action)
{
	if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action))
	{
		// 在此監聽wifi有無
		int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
		switch (wifiState)
		{
			case WifiManager.WIFI_STATE_DISABLED:
			{
				Toast.makeText(context, "WIFI_STATE_DISABLED", Toast.LENGTH_LONG).show();
				break;
			}
			case WifiManager.WIFI_STATE_DISABLING:
			{
				Toast.makeText(context, "WIFI_STATE_DISABLING", Toast.LENGTH_LONG).show();
				break;
			}
			case WifiManager.WIFI_STATE_ENABLED:
			{
				Toast.makeText(context, "WIFI_STATE_ENABLED", Toast.LENGTH_LONG).show();
				break;
			}
			case WifiManager.WIFI_STATE_ENABLING:
			{
				Toast.makeText(context, "WIFI_STATE_ENABLING", Toast.LENGTH_LONG).show();
				break;
			}
			case WifiManager.WIFI_STATE_UNKNOWN:
			{
				Toast.makeText(context, "WIFI_STATE_UNKNOWN", Toast.LENGTH_LONG).show();
				break;
			}
		}
	}
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:42,代碼來源:NetConnectivity.java

示例6: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
        //獲取當前的wifi狀態int類型數據
        int mWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
        switch (mWifiState) {
            case WifiManager.WIFI_STATE_ENABLED:
                //已打開
                getWifiList();
                break;
            case WifiManager.WIFI_STATE_ENABLING:
                //打開中
                break;
            case WifiManager.WIFI_STATE_DISABLED:
                //已關閉
                break;
            case WifiManager.WIFI_STATE_DISABLING:
                //關閉中
                break;
            case WifiManager.WIFI_STATE_UNKNOWN:
                //未知
                break;
        }
    } else if (action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
        int linkWifiResult = intent.getIntExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, 123);
        Log.d("XLight", "Get WiFi Result:" + linkWifiResult);
        if (linkWifiResult == WifiManager.ERROR_AUTHENTICATING) {
            ToastUtil.showToast(getApplicationContext(), "密碼錯誤");
        }
    } else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {//wifi連接上與否
        Log.d("XLight", "網絡狀態改變");
        NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
            Log.d("XLight", "wifi網絡連接斷開");
        } else if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
            android.net.wifi.WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            //獲取當前wifi名稱
            Log.d("XLight", "連接到網絡 " + wifiInfo.getSSID());
        }
    }
}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:42,代碼來源:BindDeviceWiFiActivity.java

示例7: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
        //獲取當前的wifi狀態int類型數據
        int mWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
        switch (mWifiState) {
            case WifiManager.WIFI_STATE_ENABLED:
                //已打開
                getWifiList();
                break;
            case WifiManager.WIFI_STATE_ENABLING:
                //打開中
                break;
            case WifiManager.WIFI_STATE_DISABLED:
                //已關閉
                break;
            case WifiManager.WIFI_STATE_DISABLING:
                //關閉中
                break;
            case WifiManager.WIFI_STATE_UNKNOWN:
                //未知
                break;
        }
    } else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {//wifi連接上與否
        Log.d("XLight", "網絡狀態改變");
        NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
        if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
            Log.d("XLight", "wifi網絡連接斷開");
        } else if (info.getState().equals(NetworkInfo.State.CONNECTED)) {

            WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            android.net.wifi.WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            String ssid = wifiInfo.getSSID();
            //獲取當前wifi名稱
            Log.d("XLight", "連接到網絡 " + ssid + ssid.contains("Photon-") + ssid.length());
            if (ssid.contains("Photon-") && ssid.length() >= 11) {
                //連接成功,跳到下一個頁麵
                Intent intent1 = new Intent(getApplicationContext(), BindDeviceWiFiActivity.class);
                intent1.putExtra("type", type);
                startActivity(intent1);
                finish();
            }
        }
    }
}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:46,代碼來源:BindDeviceSearchActivity.java


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