我已经创建了这个网络共享连接,但我更愿意不共享任何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();
}
}
}
}