如何通过ADB命令发送包含多行内容的短信
可行实现方法
你之前尝试失败的核心原因是换行符需要通过两层转义校验:本地运行adb的Shell环境、Android设备端的Shell环境,直接写\n只会被识别为普通字面量,不会被解析为换行符。
方案1:Linux/macOS/WSL环境(Bash/Zsh可用)
使用ANSI-C风格引号$'...'包裹短信内容,本地Shell会自动将引号内的\n转换为真实换行符再传递给设备:
adb shell service call isms 7 i32 0 s16 "com.android.mms.service" s16 "+目标手机号" s16 "null" s16 $'This is line 1 of the SMS\nThis is line 2 of the SMS\nAnd this is line 3' s16 "null" s16 "null"
方案2:全平台通用方案
先将带换行的短信内容存入变量,再传入adb命令,避免不同Shell的转义差异:
Linux/macOS/WSL写法:
# 构造带换行的短信内容 SMS_CONTENT=$(printf "This is line 1 of the SMS\nThis is line 2 of the SMS\nAnd this is line 3") # 执行发送命令 adb shell service call isms 7 i32 0 s16 "com.android.mms.service" s16 "+目标手机号" s16 "null" s16 "$SMS_CONTENT" s16 "null" s16 "null"
Windows PowerShell写法:
# 构造带换行的短信内容,PowerShell中换行符为`n $smsContent = "This is line 1 of the SMS`nThis is line 2 of the SMS`nAnd this is line 3" # 执行发送命令,额外嵌套一层双引号避免换行被截断 adb shell service call isms 7 i32 0 s16 "com.android.mms.service" s16 "+目标手机号" s16 "null" s16 "`"$smsContent`"" s16 "null" s16 "null"
内容的提问来源于stack exchange,提问作者Kian
相关产品推荐
相关产品推荐

