Is there a way to enable or disable tethering (USB or wifi) on an android phone programmatically? Perhaps an API in android SDK or NDK or any even non-UI command to do that.
Thanks in advance.
Is there a way to enable or disable tethering (USB or wifi) on an android phone programmatically? Perhaps an API in android SDK or NDK or any even non-UI command to do that.
Thanks in advance.
 
    
    It is possible and without root access, I use the below code snipped in my apps:
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;
        }
    }
}
Your app should have the following permission:
android.permission.CHANGE_WIFI_STATE
 
    
    Take a look at this question.
Basically there are no public API's to do it. Take a look at the settings app to see how internal apps do it though. Might have some luck with that: