5

Do you have any idea how can we configure and turn on the wi-fi hotspot using the command line (ADB console)?

End Anti-Semitic Hate
  • 4,400
  • 23
  • 61
  • 100
Ashish
  • 61
  • 1
  • 1
  • 2

2 Answers2

10

You could try this:

  adb shell am start -n com.android.settings/.TetherSettings
  adb shell input keyevent 20
  adb shell input keyevent 66

The first command opens the Settings page for Tethering and Hotspot while the latter simulate key presses: Down and Enter respectively.

Note: For different Android versions you may have to adjust the simulation of key presses depending on where the hotspot setting is located under settings.


Special Credits : Firelord and Kristopher

Firelord originally posted this as a comment, so I put this as an answer as comments are easily deleted or difficult to find

xavier_fakerat
  • 10,065
  • 6
  • 41
  • 101
  • For android 5.0+ if this is not working then add another one more keyevent 20. Credits: Kristopher – xavier_fakerat Apr 26 '17 at 10:53
  • @xavier_fakerat where does the additional keyevent 20 go? Should it be 20 20 66 or 20 66 20? – Andrew Dec 20 '17 at 16:58
  • @Andrew 20, 20 and 66 i.e down, down, enter – xavier_fakerat Dec 20 '17 at 18:00
  • 1
    @xavier_fakerat Thank you! My phone actually has cyanogenmod on it, and enabling the hotspot is the first option in the settings, so all I needed to do was enter adb shell am start -n com.android.settings/.TetherSettings then adb shell input keyevent 66. – Andrew Dec 21 '17 at 14:27
  • @xavier_fakerat Hi, I'm getting back an error message: Warning: Activity not started, intent has been delivered to currently running top-most instance. I can't verify if that means it's not working or not, as I have a dead screen. Is this normal? I'm on Android 9.0. – Arctiic Jul 28 '19 at 03:37
  • 1
    @Arctiic This is pretty normal. It is not an error message, it is a warning sort of, the system is trying to tell you that you already have the same instance of the activity thus the system tells you that it is not going to kill and restart it, but bring the activity of your already running task into the foreground. Depending on the actual input events you should get the hotspot up with no issues ;) – xavier_fakerat Jul 28 '19 at 19:33
  • 2
    If you do this repeatedly, you need to close target app before starting activity, otherwise, activity will stay open and key events will target other controls. Hence, instead of -n, you can use -S in first command. That is : adb shell am start -S com.android.settings/.TetherSettings – Efe Aug 06 '21 at 12:14
  • upto input keyevent 20 its fine but after that I dont need enter but need keyevent to simulated toggle on off button what would that be . Android 10 ver 29 – user1874594 Aug 05 '23 at 02:20
1

EDIT: To start/stop Hotspot through adb with the help of Automate, all what you'd need to do is to create a flow in Automate implementing the logic through simple block programming, copy its URI and the use broadcast it through a shell using Activity Manager

adb shell am broadcast -a com.llamalab.automate.intent.action.START_FLOW \ -d FLOW_URI_YOU_COPIED_HERE \ -n com.llamalab.automate/.StartServiceReceiver

This will immediately execute whatever logic you have created in the flow. In our case, that was enabling Hotspot. You could also pass on extras to the flow to have more functionality

Example for sending over extra information while starting the flow

adb shell am broadcast -a com.llamalab.automate.intent.action.START_FLOW \ -d FLOW_URI_YOU_COPIED \ -n com.llamalab.automate/.StartServiceReceiver \ -e key1 value1 \ -e key2 value2

The information sent then gets captured in the Payload section of the flow beginning

Searched up the whole internet couldn't find out anything BUT then I remembered about one POWERFUL app called Automate.

Using this app, you could create a complex set of instructions to be executed in your phone by something called flows.

The app has some really beautiful UI.

Here's a video demonstrating some really simple things you could do:

https://www.youtube.com/watch?v=i53Yd30TFrU

Simply speaking, you could access ALL sorts of Android APIs that would be extremely complicated to access otherwise through ADB alone. It's a universal solution for all phones to this hotspot problem and countless others.

It also has a vibrant community tab through which you could access the millions of flows created by other people.

The app is freemium, doesn't contain ads whatsoever. The only limitation is that you could run 30 blocks simultaneously at a time.

How to start/stop an Automate flow through ADB:
https://groups.google.com/g/automate-user/c/IPmrJ4HjXwk?pli=1 https://www.reddit.com/r/AutomateUser/comments/qqmpms/how_can_i_start_a_flow_via_adb/

App Link
https://play.google.com/store/apps/details?id=com.llamalab.automate

App Documentation
https://llamalab.com/automate/

EDllT
  • 11
  • 3