Disable wifi tethering on android

余生颓废 提交于 2019-12-23 04:42:11

问题


I've found on stackoverflow the code that activates wifi-tethering programmatically on android... but how can I disable programmatically wifi tethering? Is available something like setWifiApDisable?


回答1:


This should disable the wifi tethering.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setWifiTetheringEnabled(false);
}

private void setWifiTetheringEnabled(boolean enable) {
    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);

    Method[] methods = wifiManager.getClass().getDeclaredMethods();
    for (Method method : methods) {
        if (method.getName().equals("setWifiApEnabled")) {
            try {
                method.invoke(wifiManager, null, enable);
            } catch (Exception ex) {
            }
            break;
        }
    }
}

Changing setWifiTetheringEnabled(false); to setWifiTetheringEnabled(true); will enable the wifi tethering.



来源:https://stackoverflow.com/questions/22841317/disable-wifi-tethering-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!