Is there a list of the native Android OS commands that run through a shell. I have Android 2.2.1 but any version is of interest.
In particular some commands have lengthy options, so it'd be useful to see some full example's
If you don't know what i'm talking about then try the following command as an example :
am start -a android.intent.action.SENDTO -d sms:1234567890 --es sms_body "hiya mate, how are you" --ez exit_on_sent true
http://www.openintents.org/en/
Related
Hi,
I want to learn some of the commands for use in SManager (Script Manager) for ANDROID.
https://sites.google.com/site/devwom/script-manager
Does anyone know a suitable thread with guide or commands for SManager? I tried searching the web and XDA but did not find anything myself.
Specifically I want to know the cmd line to start an app.
EDIT 1:
Spent a good few hours trying to google a solution but drawn a blank.......Maybe Shell Scripts for Linux are not same as for Android...?
I would like to be able to run a script that does the following:
Checks if a directory exists on the sdcard
then executes a command (renaming of 2 directories)
then starts a program
EDIT 2:
well a few emails with the author of SManager and I was able to write my first script to check if the app is running and then if not, to rename folders and start the other version of the app. (I have Navigon Europe as well as Navigon Australia and was looking for a solution to allow both to co exist on my One-X at the same time. As both apps share the same directory structure the issue was that starting one version would overwrite the critical files of the other).
Now with my script installed as a widget I can toggle between each version without problem.
Here is some useful information on shell language for others (credits to the author of SManager Devwom):
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
Here are some critical bits of info received during my emails with him:
Thanks a lot for your interest in SManager.
The requested commands is a mix between linux commands and android os commands.
To get info about each command you can search in google and select the preferred page.
But the commands available in each Android device depends on running rom.
To get all available commands in your device, simply execute a ls (lower case LS) in system directories, that is:
ls /system/bin
ls /system/sbin
ls /system/xbin
ls /system/usr/bin
ls /system/usr/sbin
ls /system/usr/xbin
These are the most common directories where binaries resides in android devices.
May be you also can have commands at:
ls /bin
ls /sbin
ls /usr/bin
ls /usr/sbin
usually android rooted roms have the well known busybox, to get a list all comands inside it simply execute
busybox
to get all installed packages (and running names) from your device you can execute:
pm list packages
to get info about running process
ps
or
ps aux
or
ps -aux
depending on ps version installed
If conditions are based on test bash command this command is a bit confused, because usually it is named as [, and other times it is built-in inside shell
read "test man page" to get a full list of test command flags.
To check if an app is running:
if [ -n "$(ps|grep os.tools.scriptmanager)" ] ; then
echo SManager is running
fi
To check if app is NOT running:
if [ -z "$(ps|grep os.tools.scriptmanager)" ] ; then
echo SManager is NOT running
fi
To check if a file exist:
if [ -e /sdcard/file ] ; then
echo /sdcard/file exists
fi
To check if a file exist and it is a directory:
if [ -d /sdcard/file ] ; then
echo /sdcard/file exists and is directory
fi
To rename a directory simply use mv command:
I hope you can build your script with this info.
Start app it is very easy but getting correct info to start app is a bit confused.
starting app uses "am command"
To get correct info to start app you should execute:
logcat |grep Starting
in a terminal on device
then go to launcher and launch desired app
then go back to the terminal and you will see a line with info about how to fill am command.
For example if you execute SManager
in
logcat|grep Starting
output you will see
I/ActivityManager(* 275): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=os.tools.scriptmanager/.launcherActivity } from pid 377
so to start scriptmanager you need the following command
am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n os.tools.scriptmanager/.launcherActivity
I do not know how to stop apps from command line, I usually use killall command:
killall os.tools.scriptmanager
if you do not have killall command you can use grep and awk or cut commands
kill "$(ps|grep os.tools.scriptmanager|grep -v grep|awk '{print $2;}')"
or
kill "$(ps|grep os.tools.scriptmanager|grep -v grep|cut -f5 -d" ")"
may you need adjust -f5 flag
To execute script as shortcut install SMWidgets.
Scripts usually ends with last line , ie, not special action is required, it will exit with the last executed command return code
Also you can add
exit 0
or preferred exit value, but 0 usually means OK
To end script in the middle use
exit value
where value usually it is not 0
Also it is better use mv command instead rename command.
rename command it is not linux standard, but mv command is in all linux shells.
Android shell programing it is not equals to linux shell programming but this was one of my first scripting documents many years ago and it can be used as a guide. http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
Best regards,
Devwom
Thanks, this is valuable information! It's a shame this thread didn't get more replies
I've been looking to change my wallpaper by script, but so far I haven't been succesful. With your guide, I guess I'm a step closer to my goals!
Hi.
Perhaps developer of smanager or any expert is reading...
I would like to write a script for 2 purposes. Both handle with samba share running on my ubuntu.
1st situation.: I would like to move my media, download and documents files from android to the desired folder on my Ubuntu, which is shared by samba in my LAN.
The goal is to start this script with just touching a widget.
2nd situation: I would like to copy files from my samba shared folder in ubuntu to a specific folder on sdcard in android. All files in folder on sdcard should be deleted before copying. Again just by touching a widget.
Shared folder on samba are with password and rw.
Till now I am doing it manually with esexplorer...
I would like to do it with script.
Sent from my Incredible S using xda app-developers app
Hi,
My question is if there is any way we can use all linux commands on android?
There is a quite helpful list of android commands:
https://github.com/jackpal/Android-Terminal-Emulator/wiki/Android-Shell-Command-Reference
But many of linux commands are missing for example ls works but ls -lrt | grep "^|" dont...
Thanks
From the terminal, I would like to learn how to open a file in an android app.
As an example, how would I open /storage/emulated/0/Download/test.txt in Ted lightweight text editor?
When I try this:
Code:
am start -a android.intent.action.EDIT -n fr.xgouchet.texteditor/.TedActivity -d /storage/emulated/0/Download/test.txt
I get an error that includes "Permission Denial: startActivity asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL"
I'm not sure exactly what that's about, so I try to work around it with this:
Code:
am start --user 0 -a android.intent.action.EDIT -n fr.xgouchet.texteditor/.TedActivity -d /storage/emulated/0/Download/test.txt
Now Ted editor starts, but it opens a new file and not the specified file. I tried multiple times; one time there was a message at the top saying something to the effect that the specified file could not be opened. I've also tried different test files to exclude the possibility that test.txt is corrupt.
I'm stuck. Please help!
P.S. Ted's AndroidManifest.xml is available on github. I tried posting the link but, being new to the forum, I was not permitted to do so.
------------------
OS: CM11
Device: Moto G
Relevant apps: Terminal Emulator (jackpal.androidterm 1.0.65), Ted (fr.xgouchet.texteditor 1.8.1)
1) After countless hours of trial and error, I figured it out. Entering this command in the terminal opens the file for editing in Ted:
Code:
su -c "am start -a android.intent.action.EDIT -n fr.xgouchet.texteditor/.TedActivity -d file:/storage/emulated/0/Download/test.txt"
If you are reading this thread and like to write your own shell scripts, these two commands might also come handy if your script uses both CLI and GUI utilities:
2) To see the name of the app currently in the foreground:
Code:
su -c "dumpsys window windows" | grep mCurrentFocus | cut -d'/' -f1 | cut -d' ' -f5
3) To put the terminal in the foreground again:
Code:
su -c "am start -n jackpal.androidterm/.Term"
If you know how to do 1) (see my previous post) without root privileges, please post it here.
It doesn't make sense to me that root privileges would be required to open a user-owned file in a text editor. Android is linux, after all, so I'm hoping that anything a normal user can do via the GUI can also be done from the command line.
I'm having issues with my Pixel being stuck in "pixel is starting..." with no luck retrieving my files or even opening apps.
I have been using
Code:
./adb shell pm list packages"
To get the list of packages and
Code:
./adb shell monkey -p "package name" -v 500
to try to run the package. The result is always an error. Are there any tips on what could be causing this error or how to resolve it?
Code:
.vzmsgs -v 500
bash arg: -p
bash arg: com.verizon.messaging.vzmsgs
bash arg: -v
bash arg: 500
args: [-p, com.verizon.messaging.vzmsgs, -v, 500]
arg: "-p"
arg: "com.verizon.messaging.vzmsgs"
arg: "-v"
arg: "500"
data="com.verizon.messaging.vzmsgs"
:Monkey: seed=1613020879167 count=500
:AllowPackage: com.verizon.messaging.vzmsgs
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
** No activities found to run, monkey aborted.
AFAIK the monkey tool is basically used to generate pseudo-random streams of user and system events, not to start apps. But I may err, as always ...
If you want to abuse monkey to start an app then the synthax would be
Code:
adb shell "monkey -p <package_name> -c android.intent.category.LAUNCHER 1"
where you replace <package_name> with the package name of the app you would like to launch.
BTW: Line
Code:
./adb shell pm list packages"
contains a synthax error. It should read as
Code:
./adb shell "pm list packages"
I have also tried
Code:
./adb shell am start com.verizon.messaging.vzmsgs
which results in
Code:
Error: Activity not started, unable to resolve Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.verizon.messaging.vzmsgs }
As I can see you didn't pass a valid activity.
Correct Synthax to start an app by AM is
Code:
adb shell "am start -a android.intent.action.<ACTIVITY>"
where you replace <ACTIVITY> with the activity expected by app to get launched.
Hint:
Always enquote the command line ( args ) you pass to shell ( aka Android's terminal )
FYI:
I no longer participate this thread: for me it just doesn't make sense anymore. May be others willing to help will join.
I am able to do this other commands like "pull" successfully with another android phone without any issue but not on the pixel. I cannot actually use the shell am start command successfully anywhere.
I was able to run on another device using:
Code:
./adb shell monkey -p com.verizon.messaging.vzmsgs -c android.intent.category.LAUNCHER 1
but on my pixel it fails
ADB COMMAND TO FACTORY RESET DEVICE?? I'm trying to factory reset an Android / Linux based device but I'm not sure the command?? And should I use net-hunter, terminal emulator, or SSH? PLEASE HELP
Either
Code:
adb shell "am broadcast -a android.intent.action.MASTER_CLEAR"
or
Code:
adb shell "recovery --wipe_data"
I prefer this one : am broadcast -p android -a android.intent.action.FACTORY_RESET
(needs root)
edit:
if you also need to wipe all data and system properties here is it:
am broadcast -p android -a android.intent.action.FACTORY_RESET -e "android.intent.extra.REASON" "MasterClearConfirm" --ez "android.intent.extra.WIPE_EXTERNAL_STORAGE" true --ez "com.android.internal.intent.extra.WIPE_ESIMS" true --receiver-foreground