android.net.wifi.WifiManager.getWifiState()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(295)

本文整理了Java中android.net.wifi.WifiManager.getWifiState()方法的一些代码示例,展示了WifiManager.getWifiState()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.getWifiState()方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:getWifiState

WifiManager.getWifiState介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

@Test
public void getWifiState() throws Exception {
 wifiManager.setWifiEnabled(true);
 assertThat(wifiManager.getWifiState()).isEqualTo(WifiManager.WIFI_STATE_ENABLED);
 wifiManager.setWifiEnabled(false);
 assertThat(wifiManager.getWifiState()).isEqualTo(WifiManager.WIFI_STATE_DISABLED);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void getWifiState_shouldThrowSecurityExceptionWhenAccessWifiStatePermissionNotGranted()
  throws Exception {
 shadowOf(wifiManager).setAccessWifiStatePermission(false);
 try {
  wifiManager.getWifiState();
  fail("SecurityException not thrown");
 } catch (SecurityException e) {
  // expected
 }
}

代码示例来源:origin: dongjunkun/GanK

/**
 * 获取Wifi的状态,需要ACCESS_WIFI_STATE权限
 * @param context 上下文
 * @return 取值为WifiManager中的WIFI_STATE_ENABLED、WIFI_STATE_ENABLING、WIFI_STATE_DISABLED、WIFI_STATE_DISABLING、WIFI_STATE_UNKNOWN之一
 * @throws Exception 没有找到wifi设备
 */
public static int getWifiState(Context context) throws Exception{
  WifiManager wifiManager = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE));
  if(wifiManager != null){
    return wifiManager.getWifiState();
  }else{
    throw new Exception("wifi device not found!");
  }
}

代码示例来源:origin: TeamFatCat/Easy_Transfer

/**
 * 获取当前wifi状态
 *
 * @return WIFI_STATE_DISABLING, WIFI_STATE_DISABLED
 * WIFI_STATE_ENABLING,WIFI_STATE_ENABLED
 * WIFI_STATE_UNKNOWN
 */
public int getWifiState() {
  return mWifiManager.getWifiState();
}

代码示例来源:origin: LiqiNew/MyUtils

/**
 * 检查当前wifi状态. WIFI_STATE_DISABLED : WIFI网卡不可用(1) WIFI_STATE_DISABLING :
 * WIFI网卡正在关闭(0) WIFI_STATE_ENABLED : WIFI网卡可用(3) WIFI_STATE_ENABLING :
 * WIFI网正在打开(2)(WIFI启动需要一段时间) WIFI_STATE_UNKNOWN : 未知网卡状态
 */
public int checkState() {
  return mWifiManager.getWifiState();
}

代码示例来源:origin: 18Gray/CommonUtils

/**
 * 检查当前WIFI状态
 * @param context
 * @return
 */
public int checkState(Context context)
{
  return wifiManager.getWifiState();
}

代码示例来源:origin: JackWHLiu/jackknife

public int getWifiState() {
  return mWifiManager.getWifiState();    
}

代码示例来源:origin: luhaoaimama1/zone-sdk

/**
 * 返回当前Wifi状态
 * 
 * @return
 */
public int checkState() {
  // WIFI_STATE_DISABLED WIFI关闭
  // WIFI_STATE_DISABLING WIFI正在关闭
  // WIFI_STATE_ENABLED WIFI已打开
  // WIFI_STATE_ENABLING WIFI正在打开
  // WIFI_STATE_UNKNOWN WIFI状态未知
  return mWifiManager.getWifiState();
}
/**

代码示例来源:origin: stackoverflow.com

WifiManager wifi=(WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int state=wifi.getWifiState();

代码示例来源:origin: baidusoso/WifiTransfer

public static int getWifiState(Context context) {
  WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
  if (wifiManager != null) {
    return wifiManager.getWifiState();
  }
  return WifiManager.WIFI_STATE_DISABLED;
}

代码示例来源:origin: stackoverflow.com

IntentFilter filter = new IntentFilter( WifiManager.WIFI_STATE_CHANGED_ACTION );
context.registerReceiver( wifiStateRec, filter);
WifiManager wifim = (WifiManager) context.getSystemService( Context.WIFI_SERVICE );
state = wifim.getWifiState();    // get initial state

代码示例来源:origin: qyxxjd/AndroidBasicProject

/**
 * wifi是否打开
 * @return
 */
@RequiresPermission(Manifest.permission.ACCESS_WIFI_STATE)
public boolean isEnabled() {
  return mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING ||
      mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED;
}

代码示例来源:origin: qyxxjd/BaseProject

/**
 * wifi是否打开
 */
@RequiresPermission(Manifest.permission.ACCESS_WIFI_STATE) public boolean isEnabled() {
  return mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING ||
      mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED;
}

代码示例来源:origin: AlexZhuo/AlxLocationManager

/**
 * 检查当前Wifi网卡状态
 */
public void checkNetCardState(WifiManager mWifiManager) {
  if (mWifiManager.getWifiState() == 0) {
    Log.i("AlexLocation", "网卡正在关闭");
  } else if (mWifiManager.getWifiState() == 1) {
    Log.i("AlexLocation", "网卡已经关闭");
  } else if (mWifiManager.getWifiState() == 2) {
    Log.i("AlexLocation", "网卡正在打开");
  } else if (mWifiManager.getWifiState() == 3) {
    Log.i("AlexLocation", "网卡已经打开");
  } else {
    Log.i("AlexLocation", "没有获取到状态");
  }
}

代码示例来源:origin: qyxxjd/BaseProject

/**
 * 启用/禁用 wifi
 */
@RequiresPermission(allOf = {Manifest.permission.CHANGE_WIFI_STATE,
               Manifest.permission.ACCESS_WIFI_STATE})
public void setEnabled(boolean enabled) {
  if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING ||
    mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLING) {
    return;
  }
  mWifiManager.setWifiEnabled(enabled);
}

代码示例来源:origin: stackoverflow.com

final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.getConnectionInfo().getMacAddress(); // MAC address
wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED; // true if ON

代码示例来源:origin: jjdxmashl/jjdxm_baseutils

/**
 * 尝试打开wifi
 */
private static boolean tryOpenMAC(WifiManager manager) {
  boolean softOpenWifi = false;
  if (manager != null) {
    int state = manager.getWifiState();
    if (state != WifiManager.WIFI_STATE_ENABLED
        && state != WifiManager.WIFI_STATE_ENABLING) {
      manager.setWifiEnabled(true);
      softOpenWifi = true;
    }
  }
  return softOpenWifi;
}

代码示例来源:origin: qyxxjd/AndroidBasicProject

/**
 * 启用/禁用 wifi
 * @param enabled
 */
@RequiresPermission(allOf = {
    Manifest.permission.CHANGE_WIFI_STATE,
    Manifest.permission.ACCESS_WIFI_STATE})
public void setEnabled(boolean enabled) {
  if(mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING ||
      mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLING){
    return;
  }
  mWifiManager.setWifiEnabled(enabled);
}

代码示例来源:origin: stackoverflow.com

WifiManager wManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);

if(!wManager.isWifiEnabled() && wManager.getWifiState() != WifiManager.WIFI_STATE_ENABLING)
  wManager.setWifiEnabled(true);

代码示例来源:origin: stackoverflow.com

WifiManager mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
     WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
 if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
  mWifiManager.getConnectionInfo().getRssi()
  mWifiManager.getConnectionInfo().getSsid()
 }

相关文章