adb shell am instrument [options]

作用:启动对instrument实例的监视。

参数[options]:

-e // -e选项需要放在-w选项之前

作用:提供了以键值对形式存在的测试选项。Android中提供了多种键值对,具体参见下表。
举例:-e class com.android.phone.FIncomingCallTests#testRejectCall

-r

作用:以原始形式输出测试结果。该选项通常是在性能测试时与-e perf true一起使用。

参数

-w / //在测试工程的AndroidManifest.xml中查找

作用:保持adb shell打开直至测试完成
举例:-w com.android.phone.tests/com.android.phone.runners.FunctionalTestRunner

参考表

Key Value Description
package The fully-qualified Java package name for one of the packages in the test application. Any test case class that uses this package name is executed. Notice that this is not anAndroid package name; a test package has a single Android package name but may have several Java packages within it.
class The fully-qualified Java class name for one of the test case classes. Only this test case class is executed.
#method name A fully-qualified test case class name, and one of its methods. Only this method is executed. Note the hash mark (#) between the class name and the method name.
func true Runs all test classes that extend InstrumentationTestCase.
unit true Runs all test classes that do not extend eitherInstrumentationTestCaseorPerformanceTestCase.
size [small | medium | large] Runs a test method annotated by size. The annotations are@SmallTest,@MediumTest, and @LargeTest.
perf true Runs all test classes that implement PerformanceTestCase. When you use this option, also specify the-r flag for am instrument, so that the output is kept in raw format and not re-formatted as test results.
debug true Runs tests in debug mode.
log true Loads and logs all specified tests, but does not run them. The test information appears inSTDOUT. Use this to verify combinations of other filters and test specifications.
emma true Runs an EMMA code coverage analysis and writes the output to/data//coverage.ec on the device. To override the file location, use thecoverageFile key that is described in the following entry.

Note: This option requires an EMMA-instrumented build of the test application, which you can generate with thecoverage target.

coverageFile

Overrides the default location of the EMMA coverage file on the device. Specify this value as a path and filename in UNIX format. The default filename is described in the entry for theemma key

 

adb shell am start [options]

作用:启动一个activity

举例:adb shell am start -a com.lt.test.action.SECOND

举例:adb shell am start -n com.lt.test/.MyActivity

说明:[options]与参见 http://developer.android.com/tools/help/adb.html#am

adb shell am startservice [options]

作用:启动一个service

举例:adb shell am startservice -a com.lt.test.action.ONESERVICE
举例:adb shell am startservice -n com.lt.test/.MyService

 

adb shell am force-stop
作用:强制关闭一个应用程序

举例:adb shell am force-stop com.lt.test

 

adb shell am broadcast [options]

作用:发送一个广播
举例:adb shell am broadcast -a "action_finish" (发送一个广播去关闭一个activity)
举例:adb shell am broadcast -a android.intent.action.MASTER_CLEAR(恢复出厂设置的方法,会清除内存所有内容)

举例:adb shell am broadcast -n com.lt.test/.MyBroadcast

 

adb shell pm list packages [options]

作用:列举出所有包含的package

举例:adb shell pm list packages com.lt

说明:[options]与参见 http://developer.android.com/tools/help/adb.html#pm


adb shell中的am pm命令,一些自己的见解和大多数官网的翻译。

先说下am命令,am全称activity manager,你能使用am去模拟各种系统的行为,例如去启动一个activity,强制停止进程,发送广播进程,修改设备屏幕属性等等。当你在adb shell命令下执行am命令:

am
你也可以在adb shell前执行am命令:
adb shell am start -a android.intent.action.VIEW
关于一些am命令的介绍:
start [options] :启动activity通过指定的intent参数。具体intent参数参照官方表。

startservice [options] : 启动service通过指定的intent参数。具体intent跟start命令参数相同。

force-stop : 强制停止指定的package包应用。

kill [options] :杀死指定package包应用进程,该命令在安全模式下杀死进程,不影响用户体验。参数选项:--user | all | current: 指定user进程杀死,如果不指定默认为所有users。(关于USER_ID下面会介绍到)

kill-all :杀死所有的后台进程。

broadcast [options] :发送一个intent。具体intent参数参照start命令参数。参数选项:--user | all | current: 指定user进程杀死,如果不指定默认为所有users。

instrument [options] :测试命令,不多作介绍。

profile start :在进程中运行profile,分析结果写到里。

profile stop :停止profile。

set-debug-app [options] :设置package包应用为debug模式。参数选项:-w|--persistent:等待进入调试模式,保留值。

clear-debug-app :清空之前用set-debug-app命令设置的package包应用。

以下命令查看官网:
monitor [options]
screen-compat [on|off]
display-size [reset|]
display-density
to-uri
to-intent-uri

接下来介绍pm命令,pm全称package manager,你能使用pm命令去模拟android行为或者查询设备上的应用等,当你在adb shell命令下执行pm命令:

pm
你也可以在adb shell前执行pm命令:
adb shell pm uninstall com.example.MyApp
关于一些pm命令的介绍:
list packages [options] :打印所有包,选择性的查询包列表。参数选项:-f:查看关联文件,即应用apk的位置跟对应的包名(如:package:/system/app /MusicPlayer.apk=com.sec.android.app.music);-d:查看disabled packages;-e:查看enable package;-s:查看系统package;-3:查看第三方package;-i:查看package的对应安装者(如:1、 package:com.tencent.qqmusic installer=null 2、package:com.tencent.qqpim installer=com.android.vending);-u:查看曾被卸载过的package。(卸载后又重新安装依然会被列 入);--user:The user space to query。

list permission-groups :打印所有已知的权限群组。

list permissions [options] :选择性的打印权限。参数选项:

 

list features :设备特性。硬件之类的性能。

list libraries :当前设备支持的libs。

list users :系统上所有的users。(上面提到的USER_ID查询方式,如:UserInfo{0:Primary:3}那么USER_ID为0)

path :查询package的安装位置。

install [options] :安装命令。

uninstall [options] :卸载命令。

clear :对指定的package删除所有数据。

enable :使package或component可用。(如:pm enable "package/class")

disable :使package或component不可用。(如:pm disable "package/class")

disable-user [options] :参数选项:--user : The user to disable.
grant :授权给应用。

revoke :撤销权限。

set-install-location :设置默认的安装位置。其中0:让系统自动选择最佳的安装位置。1:安装到内部的设备存储空间。2:安装到外部的设备存储空间。(这只用于调试应用程序, 使用该命令可能导致应用程序退出或者其他不适的后果)。

get-install-location :返回当前的安装位置。返回结果同上参数选项。

set-permission-enforced [true|false] :使指定权限生效或者失效。

create-user :增加一个新的USER。

remove-user :删除一个USER。

get-max-users :该设备所支持的最大USER数。(某些设备不支持该命令)


更多相关文章

  1. Android O system函数执行reboot命令失败
  2. svn在linux下的使用(svn命令行)
  3. Android选项卡的几种实现方法
  4. 我的Android进阶之旅------>Android之选项卡(TabHost)的功能和用
  5. android模拟器命令大全
  6. Android之adb命令
  7. Android开发中用到的命令——不常用就忘记了
  8. java代码控制layout_Margin参数
  9. android:通过Android命令自动编译出build.xml文件

随机推荐

  1. android手记之----Activity
  2. android pm命令
  3. Android/J2SE计算两个位置坐标之间的距离
  4. Android笔记之Ripple
  5. 移动安全测试框架MobSF(二):动态分析
  6. Android(安卓)Studio 在 win7 下的安装
  7. 如何进入android的官方开发者网站
  8. Android之自定义View的死亡三部曲之(Layou
  9. Android(安卓)实现为点击事件添加震动效
  10. Android(安卓)增强版HashMap,使用软引用