Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

I would like to activate "USB tethering" 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
share|improve this question
    
That's really cool. I tried to find other commands doing aapt dump xmltree com.android.settings.apk AndroidManifest.xml but that didn't work on my phone(aapt not found). How can I see a list of the available settings ? –  George Profenza Jul 5 '13 at 15:24
    
elinux.org/Android_aapt –  StardustOne Jul 5 '13 at 15:37
    
Thanks! I've found aapt in the build-tools folder. I can run it now. I can't seem to find com.android.settings.apk though. I've tried: find / -name 'com.android.settings.apk' on the phone, but nothing came up :( Can you please let me know where I can find com.android.settings.apk ? –  George Profenza Jul 5 '13 at 15:50

3 Answers 3

There is a pretty bad method using adb shell input tap, Get the coordinates for enable tethering and substitute

adb shell input tap <x> <y>

Or navigate to enable radio using adb shell input keyevent. Just have a look at,

adb shell input 

Again this confines to a particular device.

share|improve this answer

Try the setprop command below:

setprop sys.usb.config rndis,adb
share|improve this answer
2  
This is only part of what's needed. This won't start dnsmasq for instance. –  kroot Dec 3 '13 at 6:25

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)

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.

share|improve this answer
1  
Looking at the jb-release branch, int setUsbTethering(boolean enable); looks to be the 33rd method, not 34th. Also, I've tested both the 4.1/4.2 and 4.3/4.4 commands on a Nexus 7 with JB 4.3 and service call connectivity 33 i32 1 turns on tethering. –  Josh Holland Jun 8 at 8:36
    
@JoshHolland must have been a mistake. Thanks for fixing it! –  Léo Lam Jun 8 at 15:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.