我已经创建了这个网络共享连接,但我不希望共享任何 3G/4G 连接,因为我只需要它来访问本地 Web 服务器,如何禁用对它的访问?
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
for (Method method: wmMethods){
if (method.getName().equals("setWifiApEnabled")){
try {
WifiConfiguration netConfig = new WifiConfiguration();
netConfig.SSID = "WifiConnection";
netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
method.invoke(wifi, netConfig, true);
} catch (IllegalArgumentException e){
e.printStackTrace();
} catch (IllegalAccessException e){
e.printStackTrace();
} catch (InvocationTargetException e){
e.printStackTrace();
}
}
}
}