Android之在ubuntu上常用的am、pm命令的总结
adb shell am instrument [options] <COMPONENT>
作用:啟動(dòng)對(duì)instrument實(shí)例的監(jiān)視。
參數(shù)[options]:
-e <key> <value> // -e選項(xiàng)需要放在-w選項(xiàng)之前
作用:提供了以鍵值對(duì)形式存在的測(cè)試選項(xiàng)。Android中提供了多種鍵值對(duì),具體參見(jiàn)下表。
舉例:-e class com.android.phone.FIncomingCallTests#testRejectCall
-r
作用:以原始形式輸出測(cè)試結(jié)果。該選項(xiàng)通常是在性能測(cè)試時(shí)與-e perf true一起使用。
參數(shù) <COMPONENT>:
-w <test_package_name>/<runner_class>?//<test_package_name>和<runner_class>在測(cè)試工程的AndroidManifest.xml中查找
作用:保持adb shell打開(kāi)直至測(cè)試完成舉例:-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>
作用:啟動(dòng)一個(gè)activity
舉例:adb shell am start -a com.lt.test.action.SECOND
舉例:adb shell am start -n com.lt.test/.MyActivity
說(shuō)明:[options]與<INTENT>參見(jiàn)?http://developer.android.com/tools/help/adb.html#am
adb shell am startservice [options] <INTENT>
作用:啟動(dòng)一個(gè)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>
作用:強(qiáng)制關(guān)閉一個(gè)應(yīng)用程序
舉例:adb shell am force-stop com.lt.test
?
adb shell am broadcast [options] <INTENT>
作用:發(fā)送一個(gè)廣播
舉例:adb shell am broadcast -a "action_finish" (發(fā)送一個(gè)廣播去關(guān)閉一個(gè)activity)
舉例:adb shell am broadcast -a android.intent.action.MASTER_CLEAR(恢復(fù)出廠設(shè)置的方法,會(huì)清除內(nèi)存所有內(nèi)容)
舉例: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
說(shuō)明:[options]與<INTENT>參見(jiàn)?http://developer.android.com/tools/help/adb.html#pm
adb shell中的am pm命令,一些自己的見(jiàn)解和大多數(shù)官網(wǎng)的翻譯。
先說(shuō)下am命令,am全稱activity manager,你能使用am去模擬各種系統(tǒng)的行為,例如去啟動(dòng)一個(gè)activity,強(qiáng)制停止進(jìn)程,發(fā)送廣播進(jìn)程,修改設(shè)備屏幕屬性等等。當(dāng)你在adb shell命令下執(zhí)行am命令:
am <command>
你也可以在adb shell前執(zhí)行am命令:
adb shell am start -a?android.intent.action.VIEW
關(guān)于一些am命令的介紹:
start [options] <INTENT> :啟動(dòng)activity通過(guò)指定的intent參數(shù)。具體intent參數(shù)參照官方表。
startservice [options] <INTENT> : 啟動(dòng)service通過(guò)指定的intent參數(shù)。具體intent跟start命令參數(shù)相同。
force-stop <PACKAGE> : 強(qiáng)制停止指定的package包應(yīng)用。
kill [options] <PACKAGE> :殺死指定package包應(yīng)用進(jìn)程,該命令在安全模式下殺死進(jìn)程,不影響用戶體驗(yàn)。參數(shù)選項(xiàng):--user <USER_ID> | all | current: 指定user進(jìn)程殺死,如果不指定默認(rèn)為所有users。(關(guān)于USER_ID下面會(huì)介紹到)
kill-all :殺死所有的后臺(tái)進(jìn)程。
broadcast [options] <INTENT> :發(fā)送一個(gè)intent。具體intent參數(shù)參照start命令參數(shù)。參數(shù)選項(xiàng):--user <USER_ID> | all | current: 指定user進(jìn)程殺死,如果不指定默認(rèn)為所有users。
instrument [options] <COMPONENT> :測(cè)試命令,不多作介紹。
profile start <PROCESS> <FILE> :在<PROCESS>進(jìn)程中運(yùn)行profile,分析結(jié)果寫(xiě)到<FILE>里。
profile stop <PROCESS> :停止profile。
set-debug-app [options] <PACKAGE> :設(shè)置package包應(yīng)用為debug模式。參數(shù)選項(xiàng):-w|--persistent:等待進(jìn)入調(diào)試模式,保留值。
clear-debug-app :清空之前用set-debug-app命令設(shè)置的package包應(yīng)用。
以下命令查看官網(wǎng):
monitor [options]
screen-compat [on|off] <PACKAGE>
display-size [reset|<WxH>]
display-density <dpi>
to-uri <INTENT>
to-intent-uri <INTENT>
接下來(lái)介紹pm命令,pm全稱package manager,你能使用pm命令去模擬android行為或者查詢?cè)O(shè)備上的應(yīng)用等,當(dāng)你在adb shell命令下執(zhí)行pm命令:
pm <command>
你也可以在adb shell前執(zhí)行pm命令:
adb shell pm uninstall com.example.MyApp
關(guān)于一些pm命令的介紹:
list packages [options] <FILTER> :打印所有包,選擇性的查詢包列表。參數(shù)選項(xiàng):-f:查看關(guān)聯(lián)文件,即應(yīng)用apk的位置跟對(duì)應(yīng)的包名(如:package:/system/app /MusicPlayer.apk=com.sec.android.app.music);-d:查看disabled packages;-e:查看enable package;-s:查看系統(tǒng)package;-3:查看第三方package;-i:查看package的對(duì)應(yīng)安裝者(如:1、 package:com.tencent.qqmusic installer=null 2、package:com.tencent.qqpim installer=com.android.vending);-u:查看曾被卸載過(guò)的package。(卸載后又重新安裝依然會(huì)被列 入);--user<USER_ID>:The user space to query。
list permission-groups :打印所有已知的權(quán)限群組。
list permissions [options] <GROUP> :選擇性的打印權(quán)限。參數(shù)選項(xiàng):
?
list features :設(shè)備特性。硬件之類的性能。
list libraries :當(dāng)前設(shè)備支持的libs。
list users :系統(tǒng)上所有的users。(上面提到的USER_ID查詢方式,如:UserInfo{0:Primary:3}那么USER_ID為0)
path <PACKAGE> :查詢package的安裝位置。
install [options] <PATH> :安裝命令。
uninstall [options] <PACKAGE> :卸載命令。
clear <PACKAGE> :對(duì)指定的package刪除所有數(shù)據(jù)。
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> :參數(shù)選項(xiàng):--user <USER_ID>: The user to disable.
grant <PACKAGE_PERMISSION> :授權(quán)給應(yīng)用。
revoke <PACKAGE_PERMISSION> :撤銷權(quán)限。
set-install-location <LOCATION> :設(shè)置默認(rèn)的安裝位置。其中0:讓系統(tǒng)自動(dòng)選擇最佳的安裝位置。1:安裝到內(nèi)部的設(shè)備存儲(chǔ)空間。2:安裝到外部的設(shè)備存儲(chǔ)空間。(這只用于調(diào)試應(yīng)用程序, 使用該命令可能導(dǎo)致應(yīng)用程序退出或者其他不適的后果)。
get-install-location :返回當(dāng)前的安裝位置。返回結(jié)果同上參數(shù)選項(xiàng)。
set-permission-enforced <PERMISSION> [true|false] :使指定權(quán)限生效或者失效。
create-user <USER_NAME> :增加一個(gè)新的USER。
remove-user <USER_ID> :刪除一個(gè)USER。
get-max-users :該設(shè)備所支持的最大USER數(shù)。(某些設(shè)備不支持該命令)
總結(jié)
以上是生活随笔為你收集整理的Android之在ubuntu上常用的am、pm命令的总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Android之如何ubuntu环境下在
- 下一篇: Android之6.0 权限申请封装