更新时间:2023-01-02 10:32:35
您需要在您的清单文件中的以下权限:
You need the following permissions in your manifest file:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
然后你可以使用你的活动类以下内容:
Then you can use the following in your activity class:
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
wifiManager.setWifiEnabled(false);
使用下面的检查,如果它的启用与否
Use the following to check if it's enabled or not
boolean wifiEnabled = wifiManager.isWifiEnabled()
您会发现在this站点。