4

I am developing an application for Android 3.0 and above. I want to communicate to a PC by tethering.

How do I call the "Wireless and networks-Tethering and portable hotspot Intent" by code to enable the tethering manually?

Evan Mulawski
  • 54,662
  • 15
  • 117
  • 144

3 Answers3

2

Tested in 4.1.2, perhaps should work in 4.0 also.

Intent tetherSettings = new Intent();
tetherSettings.setClassName("com.android.settings", "com.android.settings.TetherSettings");
startActivity(tetherSettings);
Ach J
  • 510
  • 5
  • 9
  • Another way of doing the same thing [via : http://forum.xda-developers.com/showthread.php?t=690616] // load tether setting dialog Intent intent = new Intent(); intent.setAction(Intent.ACTION_MAIN); ComponentName com = new ComponentName("com.android.settings", "com.android.settings.TetherSettings"); intent.setComponent(com); startActivity(intent); – Ach J Nov 03 '12 at 16:32
1

I guess there is no option to enable the tethering by the code

Correct.

And any one could you please tell me how to call the "Wireless and networks-Tethering and portable hotspot" intent by code to enable the tethering manually.

There is no documented and supported Intent action to bring up this specific screen in the Settings app at this time.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
-1

this code just starts the tethering settings and clicks on the USB tethering checkbox (setting it on if it's off and vice versa).

adb shell am start -n com.android.settings/.TetherSettings && adb shell input keyevent 20 && adb shell input keyevent 20 && adb shell input keyevent KEYCODE_ENTER && sleep 2 && adb shell input keyevent 4
Zibri
  • 9,096
  • 3
  • 52
  • 44