I want to programatically enable the USB tethering,USB debugging in android.Is it possible.What are the system permissions to be declared in manifest file.Can someone please help me out in the coding???
Asked
Active
Viewed 782 times
4
-
Possible duplicate of [Android - enable USB tethering programmatically - there is an app that did it for 2.3](https://stackoverflow.com/questions/9913645/android-enable-usb-tethering-programmatically-there-is-an-app-that-did-it-fo) – Sagar May 25 '18 at 09:26
1 Answers
0
This code enables USB tethering
public void enableTethering() {
Object conService= getSystemService(Context.CONNECTIVITY_SERVICE);
for (Method m : obj.getClass().getDeclaredMethods()) {
if (m.getName().equals("tether")) {
try {
m.invoke(conService, "usb0");
} catch (IllegalArgumentException |
IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}

Venki WAR
- 1,997
- 4
- 25
- 38
-
-
does this require phone to be rooted ??or will it work on any android os? – justin j May 28 '18 at 04:39
-
-
In home Screen Activity oncreate() method call enableTethering() method – Venki WAR May 28 '18 at 04:52
-
I checked rooted mobile its works fine,I did n't check unrooted mobile.If you have unrooted please test this code i hope it will work. other wise you need rooted mobile for this code – Venki WAR May 28 '18 at 05:08