如何在网络共享模式下禁用互联网访问(仅限本地)?

时间:2013-10-29 17:05:32

标签: java android localhost tethering

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

}

0 个答案:

没有答案