Is it possible to activate the "USB Tethering" Android setting from the command line? I would like to activate &quot;USB tethering&quot; from within a bash script, so is there any possibility to run a command line with adb shell to change some Android settings ?
Edit1:
The following command open the needed settings but don't change anything alone :
am start -n com.android.settings/.TetherSettings

I've found TetherSettings action name from
aapt dump xmltree com.android.settings.apk AndroidManifest.xml | less +/ether

Related, but the opposite Is it possible to disable USB tethering from command line?
Running the following command as root should enable USB tethering:


service call connectivity 32 i32 1 on Ice Cream Sandwich (4.0)
service call connectivity 33 i32 1 on Jelly Bean (4.1 to 4.3)
service call connectivity 34 i32 1 on KitKat (4.4)
service call connectivity 30 i32 1 on Lollipop (5.0)
service call connectivity 31 i32 1 on Lollipop (5.1) according to an answer by Firelord
service call connectivity 30 i32 1 on Marshmallow (6.0), untested
service call connectivity 41 i32 1 on Samsung Marshmallow (6.0)
service call connectivity 33 i32 1 on Nougat (7.0)
service call connectivity 39 i32 1 on Samsung Nougat (7.0)


The first number you see in the commands is the setUsbTethering() method's number in IConnectivityManager.aidl (this depends on the Android version and doesn't exist on Gingerbread).

(Tip: to check this file for a particular Android version, select the appropriate branch.)

So what this command does is call setUsbTethering() and pass either 1 (enable USB tethering) or 0 (to disable it).

For more information, see this related question on Stack Overflow.



If you're enabling USB tethering as part of a USB reverse tethering setup, setprop sys.usb.config rndis,adb should be more than enough to get the rndis0 interface set up.