通过ADB在Android上发送短信 [英] Sending a SMS on Android through ADB

查看:1168
本文介绍了通过ADB在Android上发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用以下ADB命令在Android手机连接到计算机时从我的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?

推荐答案

简短版本:

Android 5及更低版本(此处为android 4):

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和更高版本(此处为android 9):

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"

错误方法编号(以上5和7)可能会随android版本。阅读完整的说明以了解它。

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

所有android版本的完整说明:

是的!但不能使用此命令,因为这些输入事件在睡眠模式下被阻止。
此解决方案取决于您的android版本,所以我将向您解释几乎所有版本...

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 ...

第一,请检查您是否拥有该服务通过运行isms:

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

adb shell service check isms
Service isms: found

找到答案了,很好,继续前进。服务isms具有各种选项,语法为:

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]

您可以看到com.android.internal.telephony.Isms,因此在链接选择您的Android版本(通过更改分支),然后导航至: telephony / java / com / android / internal / telephony 并打开 Isms.aidl

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

其余的我将使用android Pie(android 9)文件(链接)。

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

185 我们有:


避免sendTextForSubscriberWithSelfPermissions(...)

void sendTextForSubscriberWithSelfPermissions(...)

注意:在Android 5之前该方法名为 sendText(...)

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

这是ISMS接口中的第七个声明。因此,我们发送短信的选项是数字7。在声明的顶部,是对参数的解释。这里是一个简短的版本:

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:在android 5之后,您要使用0、1或2的SIM卡,具体取决于您的android版本(例如android 9的0-1和android 8的1-2)

  • callingPkg:将发送您的短信的软件包名称(我将在以后说明如何找到它)
  • destinationAdress:邮件接收者的电话号码

  • scAddress:仅在Android 5及更低版本中需要您的smsc(解释如下)

  • parts:您的消息!

  • sendIntends和deliveryIntents:您不在乎

  • 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

->查找您的软件包名称:
浏览您的应用程序文件或在Google Play上下载软件包名称查看器,找到您的消息应用程序并复制名称(com.android ... )

-> 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...)

->查找您的短信:
在您的应用程序->设置-> SMSC或服务中心或消息中心等中,复制数字显示(请勿更改)

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

仅在fi之前在服务中修饰字符串是由s16 integers和PendingIntent与i32声明的

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

我们有:


  • subId:0

  • callingPkg:com.android.mms

  • 目标编号:+01234567890

  • SMSC:+01000000000

  • 我的文字:Hello world!

  • sendIntends和deliveryIntents无关紧要,因此我们将0设置为默认值。

  • 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.

最后:

Android 5及更低版本(此处为android 4):

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和更高版本(此处为android 9):

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"

->批处理文件中的示例:

android 4的send.bat:

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

运行以下命令:

send.bat +01234567890 Hey you !

现在告诉我它是否适用于您的Android版本:)

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

编辑:已由 Alex P.
编辑2:已由 Neil

这篇关于通过ADB在Android上发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆