//打开wifi
class StartWifiListener implements OnClickListener{
@Override
public void onClick(View v) {
WifiManager wifiManager=(WifiManager)MainActivity.this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
System.out.println("wifi state--------->"+wifiManager.getWifiState());
Toast.makeText(MainActivity.this, "当前wifi状态为"+wifiManager.getWifiState(), 0).show();
}
}
//关闭wifi
class StopWifiListener implements OnClickListener{
@Override
public void onClick(View v) {
WifiManager wifiManager=(WifiManager)MainActivity.this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(false);
System.out.println("wifi state--------->"+wifiManager.getWifiState());
Toast.makeText(MainActivity.this, "当前wifi状态为"+wifiManager.getWifiState(), 0).show();
}
}
打开或者关闭wifi
最新推荐文章于 2022-04-14 21:22:05 发布