adb shell am instrument [options] <COMPONENT>

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

参数[options]:

-e <key> <value> // -e选项需要放在-w选项之前

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

-r

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

参数 <COMPONENT>:

-w <test_package_name>/<runner_class> //<test_package_name>和<runner_class>在测试工程的AndroidManifest.xml中查找

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

<key> <value>参考表

Key Value Description
package <Java_package_name> 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 <class_name> The fully-qualified Java class name for one of the test case classes. Only this test case class is executed.
<class_name>#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 <filename>

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] <INTENT>

作用:启动一个activity

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

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

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

adb shell am startservice [options] <INTENT>

作用:启动一个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 <PACKAGE>
作用:强制关闭一个应用程序

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

adb shell am broadcast [options] <INTENT>

作用:发送一个广播
举例: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] <INTENT>

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

举例:adb shell pm list packages com.lt

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

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

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

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

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

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

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

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

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

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

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

profile stop <PROCESS> :停止profile。

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

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

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

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

pm <command>
你也可以在adb shell前执行pm命令:
adb shell pm uninstall com.example.MyApp
关于一些pm命令的介绍:
list packages [options] <FILTER> :打印所有包,选择性的查询包列表。参数选项:-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<USER_ID>:The user space to query。

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

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

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

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

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

path <PACKAGE> :查询package的安装位置。

install [options] <PATH> :安装命令。

uninstall [options] <PACKAGE> :卸载命令。

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

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

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

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

revoke <PACKAGE_PERMISSION> :撤销权限。

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

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

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

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

remove-user <USER_ID> :删除一个USER。

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

Android之在ubuntu上常用的am、pm命令的总结相关推荐

  1. Ubuntu中常用的解/压缩命令

    Ubuntu中常用的解/压缩命令 一..tar文件 二..tar.tgz文件 三..zip文件 四..rar文件 五..tar.gz文件 六..tgz文件 一..tar文件 # 解压 tar xvf ...

  2. Ubuntu上常用快捷键使用

    Ubuntu终端常用的快捷键 Ubuntu中的许多操作在终端(Terminal)中十分的快捷,记住一些快捷键的操作更得心应手.在Ubuntu中打开终端的快捷键是Ctrl+Alt+T.其他的一些常用的快 ...

  3. Android之在ubuntu上用aapt查看apk的名字以及相关信息

    第一步:如何快速找把手机里面的apk文件本地 如果我们不知道apk的包名,我们先打开需要的apk,然后再打开终端,输入下面命令获取这个apk的包名   adb shell dumpsys activi ...

  4. lxd容器运行Android,如何在ubuntu上安装LXD容器?

    本文的主角是容器,一种类似虚拟机但更轻量级的构造.你可以轻易地在你的 Ubuntu 桌面系统中创建一堆容器! 虚拟机会虚拟出整个电脑让你来安装客户机操作系统.相比之下,容器复用了主机的 Linux 内 ...

  5. Android之在ubuntu上过滤多条关键字日志

    1 问题 比如我们在查问题的时候,需要过滤多个关键字,我平时的做法是一个终端执行下面的命令,然后几个关键字就几个终端,切换来切换去不方便看日志 adb logcat | grep **** 2 改进办 ...

  6. Ubuntu上配置nginx及相关命令

    一.安装nginx 在Ubuntu下安装Nginx有以下方法,但是如果想要安装最新版本的就必须下载源码包编译安装. 1.基于APT源安装: sudo apt-get install nginx 安装好 ...

  7. Linux下Ubuntu的常用压缩、解压缩命令,以及tar中的参数 cvf,xvf,cvzf,zxvf的区别

    .tar 文件(不压缩) # 仅打包,并非压缩 tar -xvf FileName.tar # 解包 tar -cvf FileName.tar DirName # 将DirName和其下所有文件(夹 ...

  8. Ubuntu常用解压文件命令

    针对七种常用的文件后缀,在ubuntu中常用的解压命令如下: 1. *.tar文件:tar -xvf file.tar2. *.tar.gz文件:tar -xzvf file.tar.gz3. *.g ...

  9. Ubuntu上搭建Android编译环境(1)

    外网信号不好,所以把google的原文介绍扒到这里来参考. https://source.android.com/setup/ Android 源代码 Android 是一个针对多种不同设备类型打造的 ...

最新文章

  1. Xamarin SimplerCursorAdapter 适配器(三)
  2. ArcBruTile 0.2.2
  3. MyBatis自动生成工具,开发编码好帮手
  4. 循环更新数据库java_java – 无限循环数据库检查
  5. 5G 和云原生时代的技术下半场,视频化是最大最新的确定性
  6. 关于c++ template的branching和Recursion的一段很好的描述
  7. ***工具CC***的思路及防范方法
  8. VGAE(Variational graph auto-encoders)论文及代码解读
  9. 类的带参方法有哪几部分构成?
  10. 基于UDP高性能传输协议UDT
  11. 超松弛迭代法解线性方程组c语言,超松弛迭代法解线性方程组.doc
  12. 无法装载文件或者汇编的AjaxControlToolkit
  13. vue.js组件之j间的通讯一 子组件接受父祖件数据
  14. 2023计算机考研专业课参考书目(408)
  15. 阿里云服务器使用-1-可以通过浏览器访问阿里云提供的ip地址
  16. camtasia 2022标准版录制电脑屏幕视频教程
  17. 数据库大量数据操作中事务优化方案
  18. 广告大腕江南春:广告语是老板的责任
  19. deepstream6.1-YOLOv5部署
  20. 联机棋类游戏《憋尿罐》实现源码

热门文章

  1. NET问答: Entity Framework 如何快速高效的删除表中所有记录 ?
  2. 腾讯招.NET,居然要求精通MySQL,而不是SQLServer!
  3. .NET Core + Spring Cloud:API 网关
  4. BeetleX.FastHttpApi之Vuejs扩展
  5. 在 WSL2.0 的 Ubuntu 18 里使用 Docker
  6. 使用 Windows Terminal 连接远程主机
  7. 【实战 Ids4】║ 又一个项目迁移完成(MVC)
  8. 2019年Linux与开源如何统治技术圈
  9. 同时支持EF+Dapper的混合仓储,助你快速搭建数据访问层
  10. 3分钟了解数据库事务