Android之在ubuntu上常用的am、pm命令的总结
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>參考表
| 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命令的总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android之如何ubuntu环境下在
- 下一篇: Android之6.0 权限申请封装