I've tried different ways to do it:
- Tried Connectivity Manager class which is deprecated by Android because it doesn't have a setUsbTethering method.
- Tried this method:
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
public void switchOnTethering() {
Object obj = getSystemService(Context.CONNECTIVITY_SERVICE);
for (Method m : obj.getClass().getDeclaredMethods()) {
if (m.getName().equals("tether")) {
try {
m.invoke(obj, "usb0");
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
- Tried adb shell service call connectivity 30,31,32,33,34 i32 1 command
- Tried
adb shell
su
echo "rndis" > /sys/class/android_usb/android0/functions
echo "1" > /sys/class/android_usb/android0/enable
- Tried
adb shell
su
netcfg rndis0 up
netcfg rndis0 dhcp
- The only thing that works for me Adb shell svc usb setFunctions rndis but it works only in Android 11
I need to make it for Android 7 and higher. It's okay if there is a way needs root because I have rooted device.
In Android 7.0 it was
adb shell svc usb setFunction rndisYou can also try
adb shell setprop sys.usb.config rndis