About android am commands

Source: Internet
Author: User

The android system provides an adb tool for you to execute the adb shell on the basis of the adb to execute the shell command on the mobile phone side from the PC. Like a linux system in a pc, the default path of the system is javase/bin, which is an executable program. Getprop and setprop are commonly used. Compared with common linux commands, Common commands such as find are still missing in android programs. However, you can download the busybox program, push it to the android system/bin directory, and modify the permissions of this program. You can add some common shell commands. However, the methods for using these commands are somewhat different. The execution format is as follows: busybox find ......... That is, add busybox before the original command.
Some commands provided by android are not available in linux, but are unique in android. In linux, the man command is usually used to query a command, which is somewhat different from android. In my work, it is found that the vast majority of commands are used by directly entering this command. For example, to view the usage of the pm command in the shell environment, enter pm and press Enter. In addition, the common usage of android commands is as follows: am [subcommand] [options], that is, the command is followed by a subcommand. Because it is a subcommand rather than a parameter, no -, the following parameters need to be added, for example, am start-a ***. start is a sub-command here, and-a is a parameter here. These are my summary in my daily work. It is much easier to remember them based on the summary. If there is something wrong with your knowledge, please point it out.
Next we will mainly explain a few powerful android built-in commands. The first is am. Go to the am code Am. java. Every execution of am in the shell environment starts a thread to execute Am. java main function, the main implementation of this main function is in the run method, the parameters following the am command are used as runtime parameters to pass a main method (it is not easy to pass parameters to the main function once and again after using java). The parameters later vary according to the input parameters, execute different condition branches. You can see that when the number of parameters is less than 1, The showUsage () method is executed, that is, the method used by the am command, and the most common parameter intent is described in detail. The most common am command is the start command. Let's take a look at the execution process of this command.
The code checks whether it is a start sub-Command Based on the first parameter, enters the private void runStart () throws Exception method, and then enters the key method of executing the parsing parameter private Intent makeIntent (int defUser) throws URISyntaxException. In makeIntent, The while loop is used to indicate the intent to be used based on the configuration of the input parameter 1.1, which is large, such as the intent action, the data smaller, such as flag, and the parameters. The code is very common, and no algorithm is found, but it is very practical and clear. With emotion, not everyone does not need to be able to make amazing achievements by proposing amazing algorithms. It is amazing to make the ordinary things well organized. Return to the runStart method. First, check whether am start is followed by the-S (stop) parameter. If not, call the am service to execute commands across processes. Here, the execution process of am and its start sub-commands is basically finished.
This article describes common techniques for using the am start command to start an operation and input data as follows: am-a "action"-d data, where action can be queried in the application configuration file; if you specify to start an application, you can add-n, that is, component. -The data format followed by n is package name/component name. We can directly view the amlog when starting a component in the am log. The content after cmp can be used as the data passed in by the am start command-n parameter, as shown below:

 

07-07 17:44:14.993: I/ActivityManager(222): START { act=android.intent.action.MAIN  cat=[android.intent.category.LAUNCHER]  flg=0x10200000  cmp=com.android.contacts/.activities.PeopleActivity} from pid 16116 07-07 17:44:14.993: I/ActivityManager(222): START {act=android.intent.action.MAINcat=[android.intent.category.LAUNCHER]flg=0x10200000cmp=com.android.contacts/.activities.PeopleActivity} from pid 16116

In the preceding conclusion, you can start the activity and start the service. For example, start the browser: am start-n com. android. browser/com. android. browser. BrowserActivity or am start-a android. intent. action. VIEW-d http://www.google.cn /.

Finally, I will attach the author's favorite sub-commands and Their parameter descriptions. Mastering these commands will be of great help to android debug.

"Am start: start an Activity. Options are: \ n" +
"-D: enable debugging \ n" +
"-W: wait for launch to complete \ n" +
"-- Start-profiler <FILE>: start profiler and send results to <FILE> \ n" +
"-P <FILE>: like abve, but profiling stops when app goes idle \ n" +
"-R: repeat the activity launch <COUNT> times. Prior to each repeat, \ n" +
"The top activity will be finished. \ n" +
"-S: force stop the target app before starting the activity \ n" +
"-- Opengl-trace: enable tracing of OpenGL functions \ n" +
"-- User <USER_ID> | current: Specify which user to run as; if not \ n" +
"Specified then run as the current user. \ n" +

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.