41

I would like to be able to send an actual SMS message from a shell using just the command line and not relying on any apk to do so. I am interested in sending this message between phones, not from the emulator to the phone. For example, by running the command:

service call phone 2 s16 "1234567890"

I can place a call from phone to phone using the command line. The 'service list' command shows an isms service, which I can't seem to provide the correct arguments for. I would assume that one of the args should be a PDU string but haven't had any luck so far.

apaderno
  • 28,547
  • 16
  • 75
  • 90
reproba
  • 411
  • 1
  • 5
  • 3

5 Answers5

44

In fact, this can be done but requires adb to be installed (Part of the android SDK)

adb shell am start -a android.intent.action.SENDTO -d sms:CCXXXXXXXXXX --es sms_body "SMS BODY GOES HERE" --ez exit_on_sent true
adb shell input keyevent 22
adb shell input keyevent 66

Where CCXXXXXXXXXX is country-code followed by phone number. This may not work correctly on non-standard android installations, you will need to find the correct keyevent values to pass.

arpz
  • 641
  • 5
  • 9
11

You can telnet to the emulator doing something similar to "telnet localhost 5554", where 5554 is the port the emulator is listening on. After that, you can send an sms message by doing the following:

sms send 1234 "Hello"

The 1234 can be any string of digits. Enclose the message in quotes if you are including spaces.

edit: an sms command doesn't exist in Android on real devices, it's an emulator-only feature to fake an SMS receiving not sending. It's just a convenience for emulated devices that don't have access to any actual cellular network.

cf. http://developer.android.com/guide/developing/devices/emulator.html#sms

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
Karl Curmudgeon
  • 127
  • 1
  • 3
10

How about this?

service call isms 5 s16 "+??????????" i32 0 i32 0 s16 "SMS TEXT HERE"
Dmitry
  • 183
  • 1
  • 2
  • 8
7

I don't have enough reputation points up upvote the answer given by Dmitry, but that IS the answer that works with one minor modification: At least for a US number, instead of putting a plus-sign (+) it worked for me with a "1" e.g. 17079876543 ...

service call isms 5 s16 "17079876543" i32 0 i32 0 s16 "SMS TEXT HERE"

Oh boy oh boy oh boy ... now if I can figure out how to receive SMS over the command line and combine that with emacs (in an emacs shell say - he begins to rub his hands together and crack a slanted grin ... and think about all the other command line levers we can pull!)

Mylo Stone
  • 199
  • 2
  • 8
  • Working perfectly fine. But how can I add spaces ? Spaces wont work with this. As an example if I send "SMS TEXT HERE" it only send the SMS part – rafalefighter Jan 15 '17 at 05:37
  • @gripen Hmmm, I wonder if using nested single-inside-double quotes (or vice-versa) would make a difference ... i.e. '"SMS TEXT HERE"' or "'SMS TEXT HERE'" – Mylo Stone Oct 31 '18 at 23:48
2

You can send any intent you want from the command line, so it's merely a matter of figuring out what intent can be used to send an sms, or if one doesn't exist, then writing an apk which provides such intent-to-sms capability and sending the intent to trigger that from the command line.

If you end up writing an apk to do that, think a little bit about permissions. Which user will the command line be running as - the adb shell user? any old ordinary app user? Your apk will presumably have sms permissions, but do you want to extent that to everything on the phone, or implement some security mechanism in your intent?

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • 1
    Thanks Chris, I think I am on the right track with that line of thought. So far I've managed to get pretty close with the command "am start -a android.intent.action.SENDTO -d sms:1234567890 --es sms_body ohai --ez exit_on_sent true" but I still need to figure out how to trigger the view's onClick/onEditorAction automatically. Looking through the MMS source code I found the mSendButton view that I think I need to trigger a performClick() on. If I do get a working command or pair of commands I will def update this further. – reproba Nov 01 '10 at 20:14
  • It may be that user interaction is required to go that route - if there doesn't seem to be a stage where sms permission is required, the platform design philosophy would require user approval in place of permission. So you might want to take the other half of the idea and implement your own intent-driven sms sender apk, non-interactive, with sms permission. And hopefully with some kind of security mechanism so it only works for your intended purpose. – Chris Stratton Nov 01 '10 at 20:20