在Android中命令行工具am的用法如下
usage: am [subcommand] [options]
start an Activity: am start [-D] [-W] <INTENT>
-D: enable debugging
-W: wait for launch to complete
start a Service: am startservice <INTENT>
send a broadcast Intent: am broadcast <INTENT>
start an Instrumentation: am instrument [flags] <COMPONENT>
-r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
-e <NAME> <VALUE>: set argument <NAME> to <VALUE>
-p <FILE>: write profiling data to <FILE>
-w: wait for instrumentation to finish before returning
start profiling: am profile <PROCESS> start <FILE>
stop profiling: am profile <PROCESS> stop
start monitoring: am monitor [–gdb <port>]
–gdb: start gdbserv on the given port at crash/ANR
<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.music/com.android.music.MusicBrowserActivity
啟動視頻
# am start -n com.android.music/com.android.music.VideoBrowserActivity
# am start -n com.android.music/com.android.music.MediaPlaybackActivity
啟動照相機:
# 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
google map 直接定位深圳 :
am start -a android.intent.action.VIEW geo:0,0?q=shenzhen
profile
#ps
#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();
}
}