Reputation: 117
I'm trying to send messages using adb shell commands. I sent on Android 10 but not on Android 11. I tried everything but without success. I found source code of isms service for android 11 here. I have 2 more Android 11 phones and when I test them the result is the same. To test that my shell commands are working on the device, I tried the input command and it does. I read this and still it didn't help.
The command I use:
adb shell service call isms 7 i32 0 s16 "com.android.mms.service" s16 "%number%" s16 "null" s16 "%message%" s16 "null" s16 "null"
Output of this command:
Result: Parcel(00000000 '....')
Can someone help, how do I send messages with adb shell commands on Android 11?
(I tried on Android 12 and result is same)
Upvotes: 2
Views: 6447
Reputation: 4219
If you just want to send a few test messages to your emulator and don't want to deal with adb, you can do this via the emulator itself
Upvotes: 0
Reputation: 195
The following will write the SMS message using the default messaging app but won't send it:
adb shell am start -a android.intent.action.SENDTO -d sms:+1234567890 --es sms_body "Test" --ez exit_on_sent false
.
This won't help if you want to send the message entirely in the background.
Upvotes: -2
Reputation: 7897
For a future proof way - since the numbers (5,7) change, you're better off using the isms AIDL directly. Looking at the isms as an example, we see:
redfin:/ $ service list | grep isms
104 isms: [com.android.internal.telephony.ISms]
So, looking at the isms.aidl (frameworks/base/telephony/java/com/android/internal/telephony/ISms.aidl) you'll see that '5' is now
void sendTextForSubscriber(in int subId, String callingPkg, String callingAttributionTag,
in String destAddr, in String scAddr, in String text, in PendingIntent sentIntent,
in PendingIntent deliveryIntent, in boolean persistMessageForNonDefaultSmsApp,
in long messageId);
so the suggested answer:
call isms 5 i32 1 s16 "com.android.mms" s16 "null" s16 "number" s16 "null" s16 "message" s16 "null" s16 "null" i32 0 i64 0
basically fakes the arguments (and not exactly right):
in int subId = 1
String callingPkg = "com.android.mms"
String callingAttributionTag = "null"
in String destAddr = "number"
in String scAddr = "16"
in String text = "text"
in PendingIntent sentIntent ="null" (should be i32 0)
in PendingIntent deliveryIntent = "null" (should be i32 0 also)
in boolean persistMessageForNonDefaultSmsApp = 0 = false,
in long messageId = 0 (the i64)
When you can, refer to the AIDL. It's MUCH safer, and also makes sure that you serialize the right arguments. Unfortunately, these change frequently between versions.
(source: "Android Internals", Volume II (http://NewAndroidBook.com))
Upvotes: 3
Reputation: 117
After Android 10:
adb shell service call isms 5 i32 1 s16 "com.android.mms" s16 "null" s16 "number" s16 "null" s16 "message" s16 "null" s16 "null" i32 0 i64 0
Before Android 10:
adb shell service call isms 7 i32 1 s16 "com.android.mms" s16 "number" s16 "null" s16 "message" s16 "null" s16 "null"
Upvotes: 6