adb shell am

adb shell am

am(activity manager) 是管理activity的工具,可以启动activity、服务、发送广播、关闭窗口。

启动activity:adb shell am start [options] <INTENT>

<INTENT>:可以在app的AndroidManifest.xml中得到

[options]:-n 类名,-a action,-d data,-m MIME-TYPE,-c category,-e 扩展数据,等)
详情参见 http://developer.android.com/tools/help/adb.html#am

//打开发送邮件的activity
# adb shell am start -a android.intent.action.SEND_MULTIPLE

#adb shell am start -a android.intent.action.VIEW -d  http://www.6san.com/

#adb shell am start -n com.haojike.test/.MyActivity

adb shell am start -n com.magcomm.touch/.TouchLetterActivity –es letter “e”

–es传递的是字符串,还有ei,el,ez等参数

启动service:adb shell am startservice [options] <INTENT>

#adb shell am startservice -a com.haojike.test.action.ONESERVICE
#adb shell am startservice -n com.haojike.test/.MyService

强制关闭应用:adb shell am force-stop <PACKAGE>

#adb shell am force-stop com.6san.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.6san.test/.MyBroadcast

带参数的广播,模拟手机低电环境:adb shell am broadcast -a android.intent.action.BATTERY_CHANGED –ei “level” 3 –ei “scale” 100

#adb shell am broadcast -a android.provider.Telephony.SECRET_CODE -d android_secret_code://767*3855

 

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

启动对instrument实例的监视:adb shell am instrument [options] <COMPONENT>

-e <key> <value> //以键值对形式存在的测试选项,Android中提供了多种键值对。

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

<COMPONENT>:-w <test_package_name>/<runner_class> //保持adb shell打开直至测试完成,<test_package_name>和<runner_class>在AndroidManifest.xml中查找

-w com.android.phone.tests/com.android.phone.runners.FunctionalTestRunner

6san.com

评论已关闭。