[Q] Tutorial Send SMS from Android commandline (shell) - Android Q&A, Help & Troubleshooting

Hello guys!
Please, could you point me how to achieve the following functionality?
I would like to be able to send text messages (SMS) directly from android shell/commandline. The idea is that in Android from a terminal I will invoke e.g.:
Code:
sendsms +639xxxxxxxx "The body of the message"
and the sendsms app will send the message "The body of the message" to the specified number +639xxxxxxxx. I won't be using it directly, but I'd like to call it from scripts.
At stackoverflow under 4043490 thread two methods are mentioned:
a) use adb
Code:
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
Where CCXXXXXXXXXX is country-code followed by phone number. This may not work correctly on non-standard android installations, you will need to find the correct keyevent values to pass.
b) use a service call
Code:
service call isms 5 s16 "17079876543" i32 0 i32 0 s16 "SMS TEXT HERE"
But none of them works for my rooted Alcatel OT 8008D with Android 4.2.1. If I run the adb command (a) from terminal with root rights, it complains "error: device not found".
The service call (b) ends with a message "Result: Parcel(00000000 '....')" but nothing happens, no SMS being sent. Similar behaviour has been reported at stackoverflow under thread 20680167.
Please, do you have any tips?
Thanks in advance!

Related

ADB Shell Woes

So I am trying to make a tool to use with the LG Ally for root and recovery, kind of like Unrevoked. All commands necessary can be done via ADB, all resources including adb can be placed in a resource folder.
I am having very frustrating issues as the Ally doesn't have Root on auto via adb, and adb root doesnt work properly. So I started using a batch file and fan into problems where when I issue adb shell su the script gets "stuck" in the shell and wont accept any input until the su shell terminates. If I adb shell su then close the window, the su permissions are NOT preserved.
I have moved on to visual basic, so I have a little more control, but I cannot for the life of me find out how to successfully pass commands to the shell the best I can do is open new shells for each command which is no good.
I know Im missing something and I know its something simple I just cant for the life of me figure it out
ok so I made a media player which is written in c# and it passes commands to adb...I can show you how to talk to shell via c# if you want.
Ok s how are you writing to shell one by one? Are you using a stream writer to a process?
At this point the commands are issued one by one.
I just installed vb 2k8, I think my problems lye in the deprecation of vb6 commands
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Shell("C:\android-sdk-windows\tools\adb.exe shell su")
SendKeys.Send("ls")
SendKeys.Send("{ENTER}")
End Sub
End Class
Im trying to keep it simple for now. This code will open up 2 cmd windows for some reason. and it doesnt pass the SendKeys.Send keys, I just end up with 2 cmd windows sitting at the #.
If I Shell("CMD.EXE") and try running adb commands with sendkeys, the keys sent will be jarbled, it moves around my keys (I would imagine because / is an escape char?)
I havent mucked about with vb in a few years so sorry for my noobism, Im good at bash scripting but this is very counter-intuitive
ok that is a bad way of doing it...no offense
Anyway, here's the proper way of sending shell commands one by one and getting back output...
objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.FileName = ProcessPath
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
objProcess.Start()
and you set processpath to be "cmd"
and you say objprocess.standardinput.writeline("whatever command you want")
and you say objprocess.standardoutput.readline() to return a string which you can display in a messagebox by saying "msgbox(string)"
-Hope this helps
None taken, my VB is weak like the ukraine, Im just trying to make a copy of my tool for windows, since most people use it. Thatsnks for the tips Im on the right track now, I think.
It is however giving me some trouble with objProcess.StandardInput.WriteLine...
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.FileName = "cmd"
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
objProcess.Start()
objProcess.StandardInput.WriteLine("echo TEST")
End Sub
End Class
its still super simple in testing mode. This when ran gives me the error "StandardIn has not been redirected." Thanks for the help im currently researching to see if I can figure it out. If you have any more ideals let me know
Got it, thanks
heres is the working code for a test I did
Code:
Public Class Form1
Private WithEvents objProcess As Process
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
objProcess = New Process
objProcess.StartInfo.FileName = "cmd"
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
objProcess.StartInfo.RedirectStandardInput = True
objProcess.StartInfo.UseShellExecute = False
objProcess.StartInfo.RedirectStandardOutput = True
objProcess.Start()
objProcess.StandardInput.WriteLine("C:\android-sdk-windows\tools\adb.exe kill-server")
objProcess.StandardInput.WriteLine("C:\android-sdk-windows\tools\adb.exe start-server")
objProcess.StandardInput.WriteLine("C:\android-sdk-windows\tools\adb.exe shell su")
objProcess.StandardInput.WriteLine("C:\android-sdk-windows\tools\adb.exe shell mkdir /sdcard/TEST")
End Sub
End Class
If it's useful, I have a technique to start an app, then to call the app again from the command line.
If the app is still running, it will process the command line. If it's not running, it simply launches a new instance and then processes the command line.
Let me know if you can use it.
Cheers
You Guys should look at the AndroidLib.dll it has adb/fastboot and device libraries already so you can just package 1 exe in your distro without the need to include or reference Adb and fastboot directly. Here is an example of a Form Button to reboot in to the bootloader.
Code:
private void button1_Click(object sender, EventArgs e)
{
AdbCommand adbrebootCmd = Adb.FormAdbCommand(device, "reboot bootloader");
Adb.ExecuteAdbCommand(adbrebootCmd);
android.Dispose();
}
The library also allows you to send AdbShell commands with Root access.
Really useful.

commandline tips ?

hi, i installed sshdroid on my galaxy s2 so i am wondering if there is any way to mess around with anything like start a fone call or send a text message from the terminal ?
i am looking for programs like netcat, sshfs, aplay, ... but none can be found.
i also notice this (not sure why):
Code:
/data/data/berserker.android.apps.sshdroid # ps auxw | grep tv
2594 system 0:59 /system/bin/tvoutserver
has anybody done anything cool from the android command line ?
is there someway i can run com.cooliris.media from the commandline ?
schneidz said:
hi, i installed sshdroid on my galaxy s2 so i am wondering if there is any way to mess around with anything like start a fone call or send a text message from the terminal ?
i am looking for programs like netcat, sshfs, aplay, ... but none can be found.
i also notice this (not sure why):
Code:
/data/data/berserker.android.apps.sshdroid # ps auxw | grep tv
2594 system 0:59 /system/bin/tvoutserver
has anybody done anything cool from the android command line ?
is there someway i can run com.cooliris.media from the commandline ?
Click to expand...
Click to collapse
I don't know what sshdroid does, but for sure you can use terminal emulator or adb shell to launch apps.
The "am" command can be used to launch applications.
The example below is to open Email app:
Code:
su
Code:
am start com.android.email
to dig in more:
http://forum.xda-developers.com/showpost.php?p=30175170&postcount=3
easy for sms less easy to make a direct call:
Code:
su
Code:
service call phone 2 s16 "123456789"
where 123456789 is the number you want to call
fyi, sshdroid turns your fone into an ssh server so i can log into my fone via wifi from my fedora machine and use an actual keyboard to issue commands instead of an on-screen keyboard.
its also useful for things like scp/sftp... i can mount the fones harddrive/sd-card with sshfs on my pc but i cant mount my pc's harddrive to the fone with sshfs. is there a solution for this yet (i think the problem is that there is no fuse module for android yet) ?
this is weird:
Code:
~ # am start com.cooliris.media
sh: am: not found
~ # which am
/system/bin/am
~ # /system/bin/am start com.cooliris.media
sh: /system/bin/am: not found
~ # whoami
root
~ # service call phone 2 s16 "0151234567"
Result: Parcel(
0x00000000: ffffffff 00000022 006e004f 0079006c '...."...O.n.l.y.'
0x00000010: 00530020 0061006d 00740072 00610063 ' .S.m.a.r.t.c.a.'
0x00000020: 00640072 00410020 00490050 006d0020 'r.d. .A.P.I. .m.'
0x00000030: 00790061 00610020 00630063 00730065 'a.y. .a.c.c.e.s.'
0x00000040: 00200073 00490055 00430043 00000000 's. .U.I.C.C.....')
made a little bit more progress:
Code:
/system/bin/am start com.cooliris.media
Starting: Intent { act=android.intent.action.VIEW dat=com.cooliris.media }
Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=com.cooliris.media flg=0x10000000 }
schneidz said:
fyi, sshdroid turns your fone into an ssh server so i can log into my fone via wifi from my fedora machine and use an actual keyboard to issue commands instead of an on-screen keyboard.
its also useful for things like scp/sftp... i can mount the fones harddrive/sd-card with sshfs on my pc but i cant mount my pc's harddrive to the fone with sshfs. is there a solution for this yet (i think the problem is that there is no fuse module for android yet) ?
this is weird:
Code:
~ # am start com.cooliris.media
sh: am: not found
~ # which am
/system/bin/am
~ # /system/bin/am start com.cooliris.media
sh: /system/bin/am: not found
~ # whoami
root
~ # service call phone 2 s16 "0151234567"
Result: Parcel(
0x00000000: ffffffff 00000022 006e004f 0079006c '...."...O.n.l.y.'
0x00000010: 00530020 0061006d 00740072 00610063 ' .S.m.a.r.t.c.a.'
0x00000020: 00640072 00410020 00490050 006d0020 'r.d. .A.P.I. .m.'
0x00000030: 00790061 00610020 00630063 00730065 'a.y. .a.c.c.e.s.'
0x00000040: 00200073 00490055 00430043 00000000 's. .U.I.C.C.....')
Click to expand...
Click to collapse
Informative.. thanks!!

Notification/toast msg from root shell script possible?

Hi,
I am searching for a way to send a notification or a toast messages (Android 5 and above) from a running shell script. Is there any possibility to do so? (I am not a java developer!)
I want to be notified if my userinit.sh has completed or things like that.
Tnx,
Enkidu

Interact with notification action from ADB shell

I have an Android(7) phone and a Linux pc. By enabling USB debugging and using the terminal of my pc, I am able to read the notifications of my phone using the command:
Code:
adb shell dumpsys notification --noredact
Now, there are some notifications in android in which we can interact with the app directly from the notification. For example, in a Whatsapp notification, there are usually two buttons: Reply & Mark as read. In YouTube, there are options like Play, Turn off, Watch later. In the output of the above command, these options are visible in the following form:
actions={
[0] "Reply" -> PendingIntent{6becf48: PendingIntentRecord{87b8050 com.whatsapp startService (whitelist: +30s0ms)}}
[1] "Mark as read" -> PendingIntent{c1661e1: PendingIntentRecord{b8e3249 com.whatsapp startService (whitelist: +30s0ms)}}
}
Click to expand...
Click to collapse
I have two questions:
Can we interact with these options from adb shell? For example, is there any command like
Code:
adb shell <SOME COMMAND> 'Message to be sent in whatsapp with reply option'
which will send the text as a reply in whatsapp without opening the app?
Is it possible to swipe the notifications using any adb command? (Not the
Code:
adb shell input swipe x0 y0 x1 y1
, it requires to unlock the phone each time)
Some comments:
Here is what I found that may be relevant to this question.
I think that I have to somehow launch the specific intent linked to the mentioned PendingIntent id (in this case 6becf48 or 87b8050)
Using the command
Code:
adb shell dumpsys activity intents > output.txt
and then searching for 87b8050 in output.txt, I found the name of the intent. It was as follows:
* PendingIntentRecord{87b8050 com.whatsapp startService (whitelist: +30s0ms)}
uid=10104 packageName=com.whatsapp type=startService flags=0x0
requestIntent=act=com.whatsapp.intent.action.DIRECT_REPLY_FROM_MESSAGE dat=content://com.whatsapp.provider.contact/contacts/2256 cmp=com.whatsapp/.notification.DirectReplyService (has extras)
whitelistDuration=+30s0ms
Click to expand...
Click to collapse
Now I think that it may be possible to launch the intent
Code:
com.whatsapp.intent.action.DIRECT_REPLY_FROM_MESSAGE
using adb shell am command, and passing the intent id and message as some parameters.
(Just like we can launch Whatsapp from adb with am command, it should be possible to launch the pendingIntent also.)
I'm searching for something similar.. Did you figure this out or still exploring?
bump !

[Guide] Linux on Wear OS!

THIS IS ONLY TESTED IN WEAR OS 3 ON A GALAXY WATCH 4
THOUGH THIS SHOULD WORK ON ALL WATCHES AND OLDER VERSIONS OF WEAR OS
Requirements:
ADB installed on your computer
Have your wear OS device connected to the same network as you computer
A bit of patience, this works in a very weird way!
Downloading apks and installing them
Firstly enable adb and adb debugging over WiFi on your wear OS device
Then download the latest apks:
Termux
MultiVnc If you want a graphical environment on Linux
When you have the apks run these commands:
Code:
adb connect IP_OF_YOUR_WEAR_OS_DEVICE
You might be able to see your ip under the button for enabling adb debugging over wifi
Then run these commands in the downloads folder
Code:
adb -s " IP_OF_YOUR_WEAR_OS_DEVICE" install NAME_OF_THE_DOWNLOADED_TERMUX_APK_FILE
and
Code:
adb -s " IP_OF_YOUR_WEAR_OS_DEVICE" install NAME_OF_THE_DOWNLOADED_MULTI-VNC_APK_FILE
BE AWARE THAT YOU MIGHT HAVE TO RESTART THE ADB CONNECTION, SOMETIMES IT MAY FREEZE.
to do that run
Code:
adb disconnect
then
Code:
adb connect IP_OF_YOUR_WEAR_OS_DEVICE
Installing Linux in Termux
Stay awake sleepyhead!
To make everything easier enable the option in Termux to keep your watch awake, this will save you from so much trouble.
First open up Termux, then long press the black background.
Then press the three dots and choose the option "More...".
Scroll down until you see the option "Keep screen on", turn on that.
Keyboard?
I've discovered that there's a problem with Wear OS keyboards, for some reason they might not interact properly with certain android applications.
So open up Termux in your Wear OS device and see if you can write anything in Termux.
If that works, see if there's any enter button on your keyboard and see if it works.
If Termux gave any response to what you entered then skip this part and head straight for "The Linux multiverse!"
If the enter button doesn't work then you gotta install an android keyboard.
The best keyboard I've found that also works on round Wear OS devices is "Unexpected keyboard"
Download the keyboard and run:
Code:
adb -s " IP_OF_YOUR_WEAR_OS_DEVICE" install NAME_OF_THE_DOWNLOADED_KEYBOARD_APK_FILE
When the keyboard is installed change you default keyboard into the previously installed keyboard.
The Linux multiverse!
On your ANDROID PHONE install Andronix.
In there you will have a lot of options for installing Linux on Termux. You can choose whatever you want!
When you've chosen what you want, then Andronix will copy a command to your phones clipboard.
Oh no!
This is where you might only have a few options!
The problems is that you have to get the command from your phone to your Wear OS device, though your Wear OS device might not even let you copy and paste!
Though there is a way to bypass this, ANDROID APPS! The easiest way is to install messenger lite(not messenger for Wear OS).
First download Messenger lite. (source for the messenger download link)
Then In the downloads folder run:
Code:
adb -s " IP_OF_YOUR_WEAR_OS_DEVICE" install NAME_OF_THE_DOWNLOADED_MESSENGER_APK_FILE
Log into messenger on your phone and your Wear OS device.
On your phone send the command Andronix gave you, to yourself in messenger.
Then open up messenger on your Wear OS device and long press the command and select copy!
Now the biggest hassle is gone!
The long, really long awakening
Now that you've copied the command, enter Termux. Then long press the black background and press paste.
NOW DON'T TOUCH ANYTHING, so that you don't accidentally change anything in the command.
From your computer run:
Code:
adb shell input keyevent 66
Try to remember this command, or put it somewhere easy to copy. You'll need it pretty often. (this command serves as an enter button)
The installation of Linux will now begin, there will be some Y/N questions, just choose the default options by running:
Code:
adb shell input keyevent 66
After a while you might get questions about region, keyboard and such.
use
Code:
adb shell input keyevent 66
to scroll down when it says [MORE]
then use
Code:
adb shell input text "NUMBER/WORD"
(don't remove the parentheses)
then again use
Code:
adb shell input keyevent 66
as an enter button
It might also ask you for a vnc password, choose a small and easy password.
FINALLY LINUX!
You should now have Linux installed on your Wear Os device. Go do whatever you want with it.
Just remember that your Wear OS device uses arm, so if you wanna use x86 applications, then you gotta use Box64 if you have a 64-bit processor and Box86 if you have a 32-bit processor
Start Linux(Linux might automatically start after installation)
First run:
Code:
adb shell input text "ls"
Code:
adb shell input keyevent 66
This will run the ls command.
Look for a file closely name to start-SOME_LINUX_DISTRO.sh or start-andronix.sh
then run:
Code:
adb shell input text "./start-SOME_LINUX_DISTRO"
then
Code:
adb shell input keyevent 66
BOOM Linux is now running :3
What about GUI?
If you installed a Linux version with a graphical interface then you either gotta use a VNC to display anything on your watch
run
Code:
adb shell input text "vncserver-start"
then
Code:
adb shell input keyevent 66
then
Code:
adb shell input keyevent 66
The terminal will say " New 'remote-desktop' at :NUMBER on machine localhost "
remember that number
now exit Termux and start Mutli-Vnc
Scroll down to "New Connection"
in Address enter localhost
in port enter 590 and then the number. (If the number as is higher than 9, enter 59 and then the number)
Scroll down password and enter in the vnc password you chose earlier.
Then the scroll all the way down and press the big green "Connect" button!
You should now some something, maybe not a lot, but something"
You can manually set the resolution if you want, so that you're able to utilize the screen better, go here for a guide on that.
External GUI
If you actually wanna use the Linux installation, then you'll have to use an external device to view the desktop.
You can follow this guide here, as it's better at explaining then me.
You can also use this guide if you wanna use XSDL.
A tip for entering &, use the keyboard on the watch! Also the read the explanation of commands before you continue, you'll need it!
Command explanation!!
adb shell input text " " will enter any text into the connected adb device, %s is used for spaces
adb shell input keyevents will do any key event, like pressing enter, 66 is for enter
If something doesn't work, let me know. I might've missed something!

Categories

Resources