本文整理汇总了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;
}
}
示例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));
}
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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();
}
示例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, "当前没有网络连接,请确保你已经打开网络 ");
}
}
}
示例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;
}
}
}
}
示例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;
}
示例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());
}
}
}
示例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();
}
}
}
}
示例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;
}