android 打开wifi

 

WifiManager wifiManager = (WifiManager) MainActivity.this.getSystemService(Context.WIFI_SERVICE);

 

wifiManager.setWifiEnabled(true); // 打开关闭

 

System.out.println("wifi state --->"+ wifiManager.getWifiState());

 

Toast.makeText(MainActivity.this, "当前网卡状态为:" + wifiManager.getWifiState(), Toast.LENGTH_SHORT).show();

 

 

 

检查

 

  wifiManager=(WifiManager)WifiIsConnectActivity. this .getSystemService(Context.WIFI_SERVICE);           
  
                         System.out.println( "wifi state --->" +wifiManager.getWifiState()); 
  
                         Toast.makeText(WifiIsConnectActivity. this , "当前网卡状态为:" +wifiManager.getWifiState(), Toast.LENGTH_SHORT).show(); 

你可能感兴趣的:(android)