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


Java WifiManager.WIFI_STATE_ENABLED属性代码示例

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


在下文中一共展示了WifiManager.WIFI_STATE_ENABLED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: isWifiEnabled

public static boolean isWifiEnabled() {
    Context myContext = Globals.getContext();
    if (myContext == null) {
        throw new NullPointerException("Global context is null");
    }
    WifiManager wifiMgr = (WifiManager) myContext.getSystemService(Context.WIFI_SERVICE);
    if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
        ConnectivityManager connManager = (ConnectivityManager) myContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo wifiInfo = connManager
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        return wifiInfo.isConnected();
    } else {
        return false;
    }
}
 
开发者ID:stytooldex,项目名称:stynico,代码行数:16,代码来源:S_MVP.java

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

示例4: handleMessage

@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case WifiManager.WIFI_STATE_ENABLED:
            LogUtils.d("savor:网络变为可用");
            // 为了解决多次重复发送请求利用延时发送方式
            getSmallPlatformUrl();
            isWifi = true;
            break;
        case WifiManager.WIFI_STATE_DISABLED:
            wifi.setVisibility(View.INVISIBLE);
            isWifi = false;
            break;

    }
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:16,代码来源:LinkTvActivity.java

示例5: wifiEnable

@Rpc(description = "Turns on Wi-Fi with a 30s timeout.")
public void wifiEnable() throws InterruptedException, WifiManagerSnippetException {
    if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
        return;
    }
    // If Wi-Fi is trying to turn off, wait for that to complete before continuing.
    if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLING) {
        if (!Utils.waitUntil(
                () -> mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED,
                TIMEOUT_TOGGLE_STATE)) {
            Log.e(String.format("Wi-Fi failed to stabilize after %ss.", TIMEOUT_TOGGLE_STATE));
        }
    }
    if (!mWifiManager.setWifiEnabled(true)) {
        throw new WifiManagerSnippetException("Failed to initiate enabling Wi-Fi.");
    }
    if (!Utils.waitUntil(
            () -> mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED,
            TIMEOUT_TOGGLE_STATE)) {
        throw new WifiManagerSnippetException(
                String.format(
                        "Failed to enable Wi-Fi after %ss, timeout!", TIMEOUT_TOGGLE_STATE));
    }
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:24,代码来源:WifiManagerSnippet.java

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

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

示例8: handleMessage

@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case SENSOR_SHAKE:
            exitGameDelayed();
            playHammerAnimation();
            break;
        case EXIT_PRO:
            finish();
            break;
        case WifiManager.WIFI_STATE_ENABLED:
            break;
        case WifiManager.WIFI_STATE_DISABLED:
            mNetWorkSettingsDialog = new CommonDialog(GameActivity.this,"请连接包间wifi","连接后可查看当前酒楼是否有优惠活动"
                    , new CommonDialog.OnConfirmListener() {
                @Override
                public void onConfirm() {
                    Intent intent = new Intent();
                    intent.setAction("android.net.wifi.PICK_WIFI_NETWORK");
                    startActivity(intent);
                    finish();
                }
            }, new CommonDialog.OnCancelListener() {
                @Override
                public void onCancel() {
                    finish();
                }
            },"去连接");
            mNetWorkSettingsDialog.show();
            break;
    }
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:32,代码来源:GameActivity.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: 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

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

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

示例13: onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get the stored sort order
    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(this);
    int sortOrderOrdinal = prefs.getInt(PREF_WIFI_SORT_ORDER, SortOrder
            .NONE.ordinal());
    if (sortOrderOrdinal >= 0 && sortOrderOrdinal < SortOrder.values()
            .length) {
        sortOrder = SortOrder.values()[sortOrderOrdinal];
    }

    // Make a BroadcastReceiver to get the scan results
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final WifiManager wifi = (WifiManager) getSystemService
                    (Context.WIFI_SERVICE);
            int state = wifi.getWifiState();
            if (state != WifiManager.WIFI_STATE_ENABLED) {
                Utils.errMsg(WifiActivity.this, "WiFi is not enabled");
                return;
            }
            List<ScanResult> scanResults = wifi.getScanResults();
            // Make the ArrayList
            mNetworks = new ArrayList<WifiNetwork>(scanResults.size());
            for (ScanResult scanResult : scanResults) {
                mNetworks.add(new WifiNetwork(scanResult));
            }
            // Sort the arrays list
            Collections.sort(mNetworks);
            // Set the adapter
            mNetworkListdapter = new NetworkListAdapter();
            setListAdapter(mNetworkListdapter);
        }
    };
    registerReceiver(mReceiver, new IntentFilter(
            WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));


    // Call refresh to set the contents
    refresh();
}
 
开发者ID:KennethEvans,项目名称:Misc,代码行数:45,代码来源:WifiActivity.java

示例14: checkWifiState

public static boolean checkWifiState(Context context) {
    WifiManager wifiManger = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wifiManger.getWifiState()==WifiManager.WIFI_STATE_ENABLED;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:4,代码来源:WifiUtil.java

示例15: handleMessage

@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case CLOSE_SSDP_SERVICE:
            LogUtils.d("savor:ssdp 搜索10秒,关闭ssdp服务");
            Intent ssdpIntent = new Intent(mContext, SSDPService.class);
            mContext.stopService(ssdpIntent);
            break;
        case SAVE_BOX_INFO:
            Object obj = msg.obj;
            if(obj instanceof TvBoxInfo) {
                TvBoxInfo tvBoxInfo = (TvBoxInfo) obj;
                mSession.setTvBoxUrl(tvBoxInfo);
                mBindTvView.initBindcodeResult();
            }
            break;
        case SCAN_QR:
            LogUtils.d("二维码结果:" + msg.obj);
            if (TextUtils.isEmpty(msg.obj + "")) {
                mViewCallBack.showToast("无效的数字");
                return;
            }
            // 绑定tv
            mSession.setTVBoxUrl(msg.obj + "");
            mBindTvView.initBindcodeResult();
            break;
        case START_LINKTV:
            if(mBindTvView!=null) {
                mBindTvView.closeQrcodeDialog();
                String topNameActivity = getTopActivityName(mContext);
                if(!topNameActivity.equals(LinkTvActivity.class.getClass().getName())){
                    mBindTvView.startLinkTv();
                }
            }
        case CLOSE_DIALOG:
            if(mBindTvView!=null)
                mBindTvView.closeQrcodeDialog();
            break;
        case CALL_QRCODE:

            break;
        case CALL_CODE_ERRO:
            mViewCallBack.showToast("呼出二维码网络超时");
            break;
        case WifiManager.WIFI_STATE_ENABLED:
            LogUtils.d("savor:网络变为可用");
            // 为了解决多次重复发送请求利用延时发送方式
            getSmallPlatformUrl(true);
            break;
        case WifiManager.WIFI_STATE_DISABLED:
            LogUtils.d("savor:hotel 网络不可用重置酒店id为0");
            mSession.resetPlatform();
            mSession.setHotelid(0);
            mSenseView.hideProjection();
            stopProAndLink();
            break;
        case CHECK_PLATFORM:
            getSmallPlatformUrl(false);
            break;
        case GET_SMALL_FLATFORM:
            getSmallPlatformUrl(false);
            break;
        case REMOVE_QRCODE:
            mSession.setQrcode(null);
            break;
        case REMOVE_BOX_INFO:
            mSession.setTvBoxUrl(null);
            break;
    }
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:70,代码来源:BindTvPresenter.java


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