Send SMS using Android ADB

After a great deal of searching through Android documentation, I’ve made a simple shell script that’ll send SMS!
To send, run this script with argument 1 as the phone number(in CCIIXXXXXXX format C is for country code and I is for company code) and argument 2 as the message. Use “” if you have spaces in it.

#! /bin/bash
# Send text through adb by Madura A.
# https://market.android.com/details?id=org.jraf.android.nolock
# Please use the above app(or similar) to keep it from locking while
# using this script

# FIX: Android 4.1.1 suggested by samox86
PATH=$PATH:/system/xbin:/system/bin

ADB=/opt/android-sdk-linux/platform-tools/adb
$ADB shell am start -a android.intent.action.SENDTO -d sms:$1 --es sms_body "$2" --ez exit_on_sent true
sleep 1
$ADB shell input keyevent 22
sleep 1
$ADB shell input keyevent 66

Change $ADB according to where you’ve installed ADB. Make sure you’ve configured ADB(obviously!).

Advertisements

12 thoughts on “Send SMS using Android ADB

  1. Hello Madura, 
    great info, nice script. I tried and works perfect, but I have a problem with spaces characters. I tried “” but ignores it. any suggestion?, how I have to use the “”?
    thanks

    zaious

    Reply
  2. AWSOME!!! Where did you learn this stuff??? Can you give me the Links??? I want do do the same think for emails…

    Reply
    • I was searching for how to use ADB to send sms, and this was on stackoverflow I guess further documentation is on developer.android.com

      Reply
  3. Pingback: SendSMS via ADB (Script) « A Blog

  4. Using S2 with ICS. It previously worked fine (presumably before ICS), now was ending up in the message compose window with the message typed but not sent. Found that adding another
    sleep 1
    $ADB shell input keyevent 22
    step did the trick … (right after the first keyevent 22)

    Reply
  5. hello,
    i got an error that am and input not found. It helped to change android shell and specify full path to binaries (which I don’t understand, because it is included in $PATH on android phone)

    I am using android 4.1.1 with kernel 2.6.32-9. Everything worked ok on android 2.3.7, before.

    Anyway, many thanks for the script 🙂

    #!/bin/bash
    # Send text through adb by Madura A.
    # https://market.android.com/details?id=org.jraf.android.nolock
    # Please use the above app(or similar) to keep it from locking while
    # using this script

    ADB=/opt/android-sdk/platform-tools/adb
    $ADB shell /system/xbin/sh /system/bin/am start -a android.intent.action.SENDTO -d sms:$1 –es sms_body “$2” –ez exit_on_sent true
    sleep 1
    $ADB shell /system/xbin/sh /system/bin/input keyevent 22
    sleep 1
    $ADB shell /system/xbin/sh /system/bin/input keyevent 66

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s