Skip to content

Instantly share code, notes, and snippets.

@richard512
Last active November 16, 2021 20:44
Show Gist options
  • Save richard512/b93e92f31f0bdbdc3f3991be336ebbfe to your computer and use it in GitHub Desktop.
Save richard512/b93e92f31f0bdbdc3f3991be336ebbfe to your computer and use it in GitHub Desktop.
Send SMS Text Messages via ADB Android Debugger on Linux
#/bin/bash
phonenum="+10000000000"
smsbody="hello world"
# use adb to say "start the app we use for SMS"
# with the following information
adb shell am start \
-a android.intent.action.SENDTO \
-d sms:"$phonenum" \
--es sms_body "$smsbody" \
--ez exit_on_sent true
# wait for the GUI to do stuff
sleep 1
# press key 22 (D-pad Right)
adb shell input keyevent 22
# wait for the GUI to do stuff
sleep 1
# press key 66 (Enter)
adb shell input keyevent 66
# Note: This solution kind of sucks ass.
'
Better would be to actually build an Android app
that does something like this:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(NUMBER, null, MESSAGE, null, null);
'
@alminojunior
Copy link

can anybody help me?
I'm having trouble with android 8.0, command 22 -> "KEYCODE_DPAD_RIGHT" is not working as before.

instead of selecting the icon on the side it does not leave the text box of the message, going to the side and jumping a line.

Does anyone know any keyevent equivalent to 22 that works on andoid 8.0 ??

I am trying to send sms through adb with the following commands:

adb shell am start -a android.intent.action.SENDTO -d sms:+1-222-333-4444 --es sms_body "Test" --ez exit_on_sent true
adb shell input keyevent 22 (---->>does not work as before<<-------)
adb shell input keyevent 22
adb shell input keyevent 66

@Jonny-P
Copy link

Jonny-P commented Nov 16, 2021

I know it is an old post.

Instead of :
{22 –> “KEYCODE_DPAD_RIGHT”}

adb shell input keyevent 22

Use:
{61 –> “KEYCODE_TAB”}

adb shell input keyevent 61

Check out the list of Code Numbers for ADB Input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment