WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
Method[] methods = wifiManager.getClass().getDeclaredMethods();
boolean enabled=false;
for (Method method : methods) {
if (method.getName().equals("isWifiApEnabled")) {
try {
enabled = (Boolean) method.invoke(wifiManager);
} catch (Exception ex) {
}
break;
}
}
for (Method method : methods) {
if (method.getName().equals("setWifiApEnabled")) {
try {
method.invoke(wifiManager, null, !enabled);
} catch (Exception ex) {
}
break;
}
}
android.permission.CHANGE_WIFI_STATE
本文介绍了如何使用Java的WifiManager类来控制设备的WiFi状态,包括启用和禁用WiFi功能。
724

被折叠的 条评论
为什么被折叠?



