java adb读取短信,通过ADB在Android上发送短信

I would like to be able to send a SMS from my Android phone while it's connected to my computer using the following ADB commands

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

I've got this working however on the phone this will pop up a text message to the recipient with the body filled in and then click the send button and return to where you were. Is there any way to do this completely in the background so it would not interfere with anything happening on the phone?

解决方案

Short version :

Android 5 and older (here android 4):

adb shell service call isms 5 s16 "com.android.mms" s16 "+01234567890" s16 "+01SMSCNUMBER" s16 "Hello world !" i32 0 i32 0

Android 5 and later (here android 9):

adb shell service call isms 7 i32 0 s16 "com.android.mms.service" s16 "+1234567890" s16 "null" s16 "Hey\ you\ !" s16 "null" s16 "null"

Isms method number (5 and 7 above) may change with the android version . Read full explanation to understand it.

Full explanation for all android version :

Yes it exists ! but not with this command, because these input events are blocked in sleep mode.

This solution depends on your android version, so I'm going to explain you for almost all version ...

1st, check if you have the service isms by running :

adb shell service check isms

Service isms: found

The answer is found, good, keep moving. The service isms have various "options" the syntax is :

service call name_service option args

The service name can be found by typing :

adb shell service list

It will display a lot of services avaible, but the interesting line is :

5 isms: [com.android.internal.telephony.ISms]

You can see com.android.internal.telephony.Isms, so on this link choose your android version (by changing branch), then navigate to : telephony/java/com/android/internal/telephony and open Isms.aidl

For the rest I will take the android Pie (android 9) file (link).

On the line 185 we have :

void sendTextForSubscriberWithSelfPermissions(...)

Note : before android 5 the method is named sendText(...).

It is the 7th declaration in the interface ISMS . So our option to send a sms is the number 7. On the top of the declaratio there is the explanation of the arguments. Here a short version:

subId : after android 5, the SIM card you want to use 0, 1 or 2 depending of your android version (ex 0-1 for android 9 and 1-2 for android 8)

callingPkg : the name of the package that will send your sms (I explain how to find it later)

destinationAdress : the phone number of the message recipient

scAddress : your smsc is only need in android 5 and lower (explained after)

parts : your message !

sendIntends and deliveryIntents : you don't care

-> Find your package name :

Explore your app file or download Package Name Viewer on google play, find your message application and copy the name (com.android...)

-> Find your smsc :

In your application -> settings -> SMSC or Service Center or Message Center etc, copy the number display (DON'T CHANGE IT)

Just before finishing, in services the strings are declared by s16 and integers and PendingIntent with i32.

So for my example we have :

subId : 0

callingPkg : com.android.mms

target number : +01234567890

SMSC : +01000000000

My text : Hello world !

sendIntends and deliveryIntents we don't care so we put 0 to set it to default value.

Finally :

Android 5 and older (here android 4):

adb shell service call isms 5 s16 "com.android.mms" s16 "+01234567890" s16 "+01000000000" s16 "Hello world !" i32 0 i32 0

Android 5 and later (here android 9):

adb shell service call isms 7 i32 0 s16 "com.android.mms.service" s16 "+1234567890" s16 "null" s16 "'Hey you !'" s16 "null" s16 "null"

-> An example in a batch file :

The send.bat for android 4 :

echo off

set num=%1

shift

for /f "tokens=1,* delims= " %%a in ("%*") do set ALL_BUT_FIRST=%%b

echo %ALL_BUT_FIRST%

adb shell service call isms 5 s16 "com.android.mms" s16 "%num%" s16 "+01000000000" s16 "%ALL_BUT_FIRST%" i32 0 i32 0

run with :

send.bat +01234567890 Hey you !

Now tell me if it works with your android version :)

Edit : Corrected with information given by Alex P.

Edit 2: Corrected with information given by Neil

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
第一章 建立ANDROID应用开发环境 - 5 - 1.1 步骤一:下载并安装JDK (JAVA SE DEVELOPMENT KIT) - 5 - 1.2 步骤二:下载并安装ADT集成开发环境和ANDROID SDK - 6 - 1.2.1 下载Android SDK (API 17) - 7 - 1.2.2 启动ADT集成开发环境 (Android Developer Tools) - 8 - 1.3 步骤三:创建ANDROID模拟器 - 9 - 1.4 步骤四:开发第一个ANDROID程序 (验证开发环境是否搭建成功) - 11 - 1.4.1 创建HelloWorld工程 - 11 - 1.4.2 在模拟器运行Android程序 - 13 - 1.5 步骤五:建立TINY4412调试环境 - 13 - 1.5.1 安装USB ADB驱动程序 - 13 - 1.5.2 在Tiny4412上测试ADB功能 - 14 - 1.5.3 通过USB ADB在Tiny4412上运行程序 - 16 - 1.5.4 在Tiny4412上调试Android程序 - 18 - 第二章 在ANDORID程序中访问硬件 - 20 - 2.1 如何使用函数库(LIBFRIENDLYARM-HARDWARE.SO)? - 20 - 2.2 函数库(LIBFRIENDLYARM-HARDWARE.SO)接口说明 - 22 - 2.2.1 通用的输入输出接口 - 22 - 2.2.2 串口通讯的接口说明 - 23 - 2.2.3 开关LED的接口说明 - 24 - 2.2.4 让PWM蜂鸣器发声和停止发声的接口说明 - 24 - 2.2.5 读取ADC的转换结果的接口说明 - 24 - 2.2.6 I2C接口说明 - 25 - 2.2.7 SPI接口说明 - 26 - 2.2.8 GPIO接口说明 - 28 - 2.3 示例程序说明 - 29 - 2.3.1 在板LED示例 - 29 - 2.3.2 GPIO示例 - 30 - 2.3.3 串口通讯示例 - 34 - 2.3.4 PWM示例 - 35 - 2.3.5 A/D转换示例 - 36 - 2.3.6 I2C& EEPROM示例 - 36 - 2.3.7 SPI示例 - 37 - 2.4 在ADT中导入示例工程 - 37 -

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值