在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();
}
}