Disable wifi tethering on android
Asked Answered
B

1

0

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?

Bernina answered 3/4, 2014 at 14:52 Comment(0)
B
5

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.

Berley answered 3/4, 2014 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.