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


Java WifiManager.WIFI_STATE_ENABLING屬性代碼示例

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


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

示例1: onReceive

@Override
public void onReceive(Context context, @NonNull Intent intent)
{
    int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);

    switch (wifiState)
    {
        case WifiManager.WIFI_STATE_ENABLED:
            wifiStateCallback.onWifiEnabled();
            break;
        case WifiManager.WIFI_STATE_ENABLING:
            break;
        case WifiManager.WIFI_STATE_DISABLING:
            break;
        case WifiManager.WIFI_STATE_DISABLED:
            break;
    }
}
 
開發者ID:ThanosFisherman,項目名稱:WifiUtils,代碼行數:18,代碼來源:WifiStateReceiver.java

示例2: wifiDisable

@Rpc(description = "Turns off Wi-Fi with a 30s timeout.")
public void wifiDisable() throws InterruptedException, WifiManagerSnippetException {
    if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED) {
        return;
    }
    // If Wi-Fi is trying to turn on, wait for that to complete before continuing.
    if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) {
        if (!Utils.waitUntil(
                () -> mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED,
                TIMEOUT_TOGGLE_STATE)) {
            Log.e(String.format("Wi-Fi failed to stabilize after %ss.", TIMEOUT_TOGGLE_STATE));
        }
    }
    if (!mWifiManager.setWifiEnabled(false)) {
        throw new WifiManagerSnippetException("Failed to initiate disabling Wi-Fi.");
    }
    if (!Utils.waitUntil(
            () -> mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED,
            TIMEOUT_TOGGLE_STATE)) {
        throw new WifiManagerSnippetException(
                String.format(
                        "Failed to disable Wi-Fi after %ss, timeout!", TIMEOUT_TOGGLE_STATE));
    }
}
 
開發者ID:google,項目名稱:mobly-bundled-snippets,代碼行數:24,代碼來源:WifiManagerSnippet.java

示例3: 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

示例4: 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

示例5: run

@Override
public void run() {
    // 打開wifi
    openWifi();
    // 開啟wifi功能需要一段時間(我在手機上測試一般需要1-3秒左右),所以要等到wifi
    // 狀態變成WIFI_STATE_ENABLED的時候才能執行下麵的語句
    while (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) {
        try {
            // 為了避免程序一直while循環,讓它睡個100毫秒檢測……
            Thread.sleep(100);

        } catch (InterruptedException ie) {
            LogUtils.e(ie.toString());
        }
    }

    WifiConfiguration tempConfig = isExsits(ssid);

    if (tempConfig != null) {
        boolean b = wifiManager.enableNetwork(tempConfig.networkId,
                true);
    } else {
        WifiConfiguration wifiConfig = createWifiInfo(ssid, password,
                type);
        if (wifiConfig == null) {
            LogUtils.d("wifiConfig is null!");
            return;
        }

        int netID = wifiManager.addNetwork(wifiConfig);
        boolean enabled = wifiManager.enableNetwork(netID, true);
        LogUtils.d("enableNetwork status enable=" + enabled);
        boolean connected = wifiManager.reconnect();
        LogUtils.d("enableNetwork connected=" + connected);
    }

}
 
開發者ID:Horrarndoo,項目名稱:YiZhi,代碼行數:37,代碼來源:WifiAutoConnectManager.java

示例6: updateWiFiState

private void updateWiFiState(int wifiState) {

		int state;
		int actionState;
		switch (wifiState) {
		case WifiManager.WIFI_STATE_DISABLING:
			state = R.string.txt_status_turning_off;
			actionState = STATE_INPROCESS;
			break;

		case WifiManager.WIFI_STATE_DISABLED:
			state = R.string.txt_status_turned_off;
			actionState = STATE_DONE;
			break;

		case WifiManager.WIFI_STATE_ENABLING:
			state = R.string.txt_status_turning_on;
			actionState = STATE_INPROCESS;
			break;

		case WifiManager.WIFI_STATE_ENABLED:
			state = R.string.txt_status_turned_on;
			actionState = STATE_DONE;
			break;

		default:
			state = R.string.txt_status_unknown;
			actionState = STATE_DONE;
			break;
		}

		String stateText = mActivity.getString(state);
		setActionState(actionState);

		// update description
		Setting setting = mSetting;
		setting.descr = stateText;
		setting.checked = wifiState == WifiManager.WIFI_STATE_ENABLED || wifiState == WifiManager.WIFI_STATE_DISABLING;
		setting.updateView();
	}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:40,代碼來源:WiFiSettingHandler.java

示例7: 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

示例8: 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

示例9: isWifiOpen

public static boolean isWifiOpen(Context context) {
    WifiManager wifiManager = (WifiManager) context
            .getSystemService(Context.WIFI_SERVICE);
    int state = wifiManager.getWifiState();
    boolean flag = false;
    if (state == WifiManager.WIFI_STATE_ENABLED
            || state == WifiManager.WIFI_STATE_ENABLING) {
        flag = true;
    }
    return flag;
}
 
開發者ID:kamisakihideyoshi,項目名稱:TaipeiTechRefined,代碼行數:11,代碼來源:WifiUtility.java

示例10: 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

示例11: 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

示例12: isWifiOpen

/**
 * 判斷Wifi是否打開,需要ACCESS_WIFI_STATE權限
 *
 * @param context 上下文
 * @return true:打開;false:關閉
 */
public static boolean isWifiOpen(Context context) throws Exception {
    int wifiState = getWifiState(context);
    return wifiState == WifiManager.WIFI_STATE_ENABLED || wifiState == WifiManager.WIFI_STATE_ENABLING;
}
 
開發者ID:liying2008,項目名稱:Simpler,代碼行數:10,代碼來源:NetWorkUtils.java


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