android am 命令总结

文章出处: http://blog.csdn.net/shift_wwx
Android在shell中提供了 am 命令来发送Intent,它的源码为位于 frameworks/base/cmds/am.
它本身是用JAVA代码来实现的。
执行 am 命令其实是通过运行shell脚本 frameworks/base/cmds/am/am,然后在该脚本中运行 app_process 命令来启动am这个java程序的。
frameworks/base/cmds/am/am脚本文件如下:

# Script to start "am" on the device, which has a very rudimentary
# shell.
#
base=/system
export CLASSPATH=$base/framework/am.jar
exec app_process $base/bin com.android.commands.am.Am "$@"

am命令语法如下
usage: am [subcommand] [options]
 
CommandDescription
start [options] <INTENT>Start an Activity specified by<INTENT>.

See the Specification for <INTENT> arguments.

Options are:

  • -D: Enable debugging.
  • -W: Wait for launch to complete.
  • --start-profiler <FILE>: Start profiler and send results to <FILE>.
  • -P <FILE>: Like --start-profiler, but profiling stops when the app goes idle.
  • -R: Repeat the activity launch <COUNT> times. Prior to each repeat, the top activity will be finished.
  • -S: Force stop the target app before starting the activity.
  • --opengl-trace: Enable tracing of OpenGL functions.
  • --user <USER_ID> | current: Specify which user to run as; if not specified, then run as the current user.

startservice [options] <INTENT>Start the Service specified by<INTENT>.

See the Specification for <INTENT> arguments.

Options are:

  • --user <USER_ID> | current: Specify which user to run as; if not specified, then run as the current user.

force-stop <PACKAGE>Force stop everything associated with <PACKAGE> (the app's package name).
kill [options] <PACKAGE>Kill all processes associated with <PACKAGE> (the app's package name). This command kills only processes that are safe to kill and that will not impact the user experience.

Options are:

  • --user <USER_ID> | all | current: Specify user whose processes to kill; all users if not specified.

kill-all

Kill all background processes.

broadcast [options] <INTENT> Issue a broadcast intent.

See the Specification for <INTENT> arguments.

Options are:

  • [--user <USER_ID> | all | current]: Specify which user to send to; if not specified then send to all users.
instrument [options] <COMPONENT>Start monitoring with an Instrumentation instance. Typically the target<COMPONENT> is the form<TEST_PACKAGE>/<RUNNER_CLASS>.

Options are:

  • -r: Print raw results (otherwise decode <REPORT_KEY_STREAMRESULT>). Use with[-e perf true] to generate raw output for performance measurements.
  • -e <NAME> <VALUE>: Set argument <NAME> to <VALUE>. For test runners a common form is-e <testrunner_flag> <value>[,<value>...].
  • -p <FILE>: Write profiling data to <FILE>.
  • -w: Wait for instrumentation to finish before returning. Required for test runners.
  • --no-window-animation: Turn off window animations while running.
  • --user <USER_ID> | current: Specify which user instrumentation runs in; current user if not specified.
profile start <PROCESS> <FILE>Start profiler on <PROCESS>, write results to <FILE>.
profile stop <PROCESS>Stop profiler on <PROCESS>.
dumpheap [options] <PROCESS> <FILE>Dump the heap of <PROCESS>, write to <FILE>.

Options are:

  • --user [<USER_ID>|current]: When supplying a process name, specify user of process to dump; uses current user if not specified.
  • -n: Dump native heap instead of managed heap.
set-debug-app [options] <PACKAGE>Set application <PACKAGE> to debug.

Options are:

  • -w: Wait for debugger when application starts.
  • --persistent: Retain this value.
clear-debug-app Clear the package previous set for debugging with set-debug-app.
monitor [options] Start monitoring for crashes or ANRs.

Options are:

  • --gdb: Start gdbserv on the given port at crash/ANR.

screen-compat [on|off] <PACKAGE> Control screen compatibility mode of <PACKAGE>.
display-size [reset|<WxH>] Override emulator/device display size. This command is helpful for testing your app across different screen sizes by mimicking a small screen resolution using a device with a large screen, and vice versa.

Example:
am display-size 1280x800

display-density <dpi> Override emulator/device display density. This command is helpful for testing your app across different screen densities on high-density screen environment using a low density screen, and vice versa.

Example:
am display-density 480

to-uri <INTENT> Print the given intent specification as a URI.

See the Specification for <INTENT> arguments.

to-intent-uri <INTENT> Print the given intent specification as an intent: URI.

See the Specification for <INTENT> arguments.


 
<INTENT> specifications include these flags:
[-a <ACTION>]
[-d <DATA_URI>]
[-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--esn <EXTRA_KEY> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[-n <COMPONENT>]
[-f <FLAGS>]
[--grant-read-uri-permission] [--grant-write-uri-permission]
[--debug-log-resolution]
[--activity-brought-to-front] [--activity-clear-top]
[--activity-clear-when-task-reset] [--activity-exclude-from-recents]
[--activity-launched-from-history] [--activity-multiple-task]
[--activity-no-animation] [--activity-no-history]
[--activity-no-user-action] [--activity-previous-is-top]
[--activity-reorder-to-front] [--activity-reset-task-if-needed]
[--activity-single-top]
[--receiver-registered-only] [--receiver-replace-pending]
[<URI>]
 

启动的方法为一个activity

# am start -n 包名/包名.活动(activity)名称
   启动的哪个acitivity方法可以从每个应用的AndroidManifest.xml的文件中找到信息
 

启动照相机:

# am start -n com.android.camera/com.android.camera.Camera

启动浏览器

# am start -n com.android.browser/com.android.browser.BrowserActivity

启动浏览器并上网:

#am start -a android.intent.action.VIEW -d http://www.google.cn/

打电话 :

#am start -a android.intent.action.CALL -d tel:10086

 

profile

#am profile 进程号 start profile_result.txt

#am profile 进程号 stop

 

启动一个service

#am startservice service的intent

 

启动instrument测试(界面上是进dev tools -->instrument选择)

看看浏览器测试工程的xml文件

<application>
        <uses-library android:name="android.test.runner" />
</application>

    <!--
    This declares that this app uses the instrumentation test runner targeting
    the package of com.android.email.  To run the tests use the command:
    "adb shell am instrument -w com.android.browser.tests/android.test.InstrumentationTestRunner"
    -->
    <instrumentation android:name="android.test.InstrumentationTestRunner"
                     android:targetPackage="com.android.browser"
                     android:label="Tests for Browser."/>

    <instrumentation android:name="com.android.browser.BrowserLaunchPerformance"
        android:targetPackage="com.android.browser"
        android:label="Browser Launch Performance">
    </instrumentation>

 

 

将当前浏览器加到单元测试中

# am instrument -w com.android.Browser/android.test.InstrumentationTestRunner

运行某个TestCase:
# am instrument -w -e class com.android.BrowserTest.PopularUrlsTest com.android.Browser/android.test.InstrumentationTestRunner

运行一个TestCase中的某个功能:
adb shell am instrument -w -e class com.android.BrowserTest.PopularUrlsTest#testStability com.android.Browser/android.test.InstrumentationTestRunner

同时测试多个TestCase:
#am instrument -w -e class com.android.BrowserTest.PopularUrlsTest,TestWebViewClient.java com.android.Browser/android.test.InstrumentationTestRunner

 

public class ApiDemosRunner extends InstrumentationTestRunner{
    @Override
    public TestSuite getAllTests(){
        Log.i(”ApiDemosRunner”, “ApiDemosRunner::getAllTests()”);
        return new TestSuiteBuilder(ApiDemosRunner.class).includeAllPackagesUnderHere().build();   
    }
    
    @Override
    public ClassLoader getLoader(){
        return ApiDemosRunner.class.getClassLoader();
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: Android系统是一种基于Linux内核的操作系统,而Android的Shell命令则是在Android系统中运行的命令。下面是一些常用的Android Shell命令的简要介绍: 1. adb:Android Debug Bridge的缩写,是一种用于与Android设备进行通信的命令行工具,可用于安装应用程序、传输文件、执行命令等。 2. am:Android Activity Manager的缩写,用于管理Android应用程序的活动(Activity)和服务(Service),可以启动、停止、打开、关闭等。 3. pmAndroid Package Manager的缩写,用于管理Android应用程序的安装包(APK文件),可以安装、卸载、查询应用程序等。 4. wm:Android Window Manager的缩写,用于管理Android窗口和显示,可以设置屏幕分辨率、旋转屏幕、调整窗口大小等。 5. input:用于模拟用户输入,可以发送触摸事件、按键事件等。 6. su:切换到超级用户(root)权限,可以执行一些需要root权限才能进行的操作。 7. cd:切换当前目录。 8. ls:显示当前目录下的文件和目录。 9. mkdir:创建新的目录。 10. cp:复制文件或目录。 11. mv:移动文件或目录。 12. rm:删除文件或目录。 13. cat:显示文件内容。 14. ps:显示正在运行的进程列表。 15. top:实时显示系统资源使用情况。 这些只是Android Shell命令的一小部分,Android提供了更多的命令可以用于开发、调试和管理Android设备。对于想要深入了解Android Shell命令的开发者来说,可以查阅更详尽的Android开发者文档或其他相关资料。 ### 回答2: Android是一种基于Linux内核的开源操作系统,它具有强大的命令行界面及Shell命令集。以下是一些常用的Android Shell命令集合: 1. adb命令Android Debug Bridge,用于与Android设备通信,例如adb shell用于进入设备的Shell环境。 2. su命令:切换到超级用户权限,用于执行需要root权限才能操作的命令。 3. pm命令:Package Manager,用于管理、安装、卸载应用程序。例如pm list packages显示已安装的包名列表。 4. am命令:Activity Manager,用于启动Activity、发送广播等操作。例如am start -n com.example.app/.MainActivity启动应用程序的主界面。 5. input命令:模拟用户输入,例如input tap模拟点击屏幕、input keyevent模拟按键事件。 6. dumpsys命令:获取系统服务的信息。例如dumpsys battery获取电池信息、dumpsys meminfo获取内存使用情况。 7. settings命令:用于访问和修改系统设置,例如settings put system screen_brightness 100设置屏幕亮度为最大值。 8. pm命令:Package Manager,用于管理、安装、卸载应用程序。例如pm install /sdcard/app.apk安装应用程序。 9. getprop和setprop命令:用于获取和设置系统属性。例如getprop ro.build.version获取系统版本号。 10. logcat命令:用于查看设备的日志信息。例如logcat -d打印设备的日志。 这些只是Android Shell命令中的一小部分,通过这些命令可以对Android设备进行各种操作和管理。具体使用时可以参考相关的文档和教程。 ### 回答3: Android shell命令是一组能在Android设备上执行的命令集合,它在设备系统级别上提供了许多功能和控制选项。以下是一些常用的Android shell命令: 1. adb shell:通过adb(Android调试桥)连接到设备上的shell。 2. ls:列出目录中的文件和子目录。 3. cd:切换当前工作目录。 4. cp:复制文件或目录。 5. mv:移动文件或目录。 6. rm:删除文件或目录。 7. cat:查看文件内容。 8. echo:打印文本到终端或文件。 9. ps:显示当前运行中的进程。 10. top:显示当前系统资源使用情况和进程列表。 11. kill:终止指定的进程。 12. chmod:修改文件或目录的权限。 13. chown:修改文件或目录的所有者。 14. ifconfig:显示网络接口配置信息。 15. ping:测试网络连接和延迟。 16. netstat:显示网络连接和路由表。 17. mount:挂载文件系统。 18. umount:卸载文件系统。 19. getprop:获取设备属性信息。 20. grep:在文件或文本中搜索指定的模式。 这只是常用命令的一小部分,Android shell命令非常丰富,可以用于执行各种系统管理、文件操作、进程管理、网络配置和调试等任务。通过使用这些命令,开发者可以更好地理解和控制Android设备。请注意,使用这些命令时需要小心,以免对系统造成不可逆的影响。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

私房菜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值