This article provides some guidance and examples of commands that can be sent through the command interface to Android Devices. To see example commands for Windows and Linux Devices, see the following articles:
Timeouts
If a supplied command does not return within 60 seconds, the UI will display a timeout message.
If a command does not return at all (e.g. it spawns a sub-prompt for further input), subsequent use of the command interface will fail until 5 minutes has passed. At this point, the interface kills the process so that further commands are possible.
Application Control
Starting an App
To start an app using the Monkey tool:
monkey -p com.company.package_name -c android.intent.category.LAUNCHER 1
For more information on the monkey command line tool, see the following android.com developer page: UI/Application Exerciser Monkey | Android Developers
In cases where the monkey tool is not available, the Activity Manager may be used instead, as follows:
am start -n com.company.package_name/.activity_name
Note that both the package name and activity name are required, and the activity name should be the LAUNCHER category activity. This is typically (though not always) MainActivity.
Some experimentation may have to be done to find out which activity is the root LAUNCHER activity. For example, use “dumpsys” to list all of the activities in a given package, as follows:
dumpsys package | grep package_name | grep Activity
Stopping an App
Use the following command to stop an application using the package name:
am force-stop com.company.package_name
Listing installed packages
To see a list of the available packages installed on a device, use the Android Package Manager, as follows:
pm list packages -3
Note that the -3 option will list only third party apps. To list the built in application package names, remove the -3 option.
Shell Commands
Example Command |
Description |
mkdir /sdcard/Android/CustomApp/logs |
Make a new directory |
rm -rf /data/data/tmp/CustomApp |
Remove a directory |
/sdcard/Android/data/com.company.customapp/scripts/install_checkup.sh |
Run a custom script |
Android Agent Command Line Escape Sequences
The following commands have been added to the Android SquareOne Agent to add useful features that are not natively provided by the Android shell.
Please note that if one of the following escape sequences is found in the command line, it will be intercepted and only the escape sequence will be processed. This also means that shell features such as piping or I/O redirection will not be available.
--update_package: OTA Update Package
Usage: --update_package=<path/to/OTA_Update_zip_file>
Example: --update_package=/sdcard/Download/OTA_Update_SystemRelease-1.0.3.zip
The update_package command will hand a OTA Update zip file package to the Android Package Manager for processing. For more information, see OTA Updates | Android Open Source Project
--start_app: Start An Application
Usage: --start_app=<Application ID>
Example: --start_app=com.bsquare.provisionapp
The start_app command will use the Android Activity Manager (ActivityManager | Android Developers) to start an Android Java Application. The “com.company.app” is the Android Application ID that uniquely identifies an Android Application (Configure the app module | Android Developers).
--stop_app: Stop An Application
Usage: --stop_app=<Application ID>
Example: --stop_app=com.bsquare.provisionapp
The stop_app command will use the Android Activity Manager (ActivityManager | Android Developers) to stop an Android Java Application. The “com.company.app” is the Android Application ID that uniquely identifies an Android Application (Configure the app module | Android Developers).
--delayed_reboot: Delayed Reboot
Usage: --delayed_reboot=<delay time in seconds>
Example: --delayed_reboot=10
The delayed_reboot command will start a background process which reboots the device after the provided number of seconds have elapsed. This is an asynchronous process that allows communications to continue while reboot is prepared.
--get_process_list: Get Java Application Process List
Usage: --get_process_list
The get_proccess_list command returns a list of Application IDs for the Java applications currently running. Each item in the list will be separated with a “\r\n”.