适用于Linux 环境 和 adb shell 下
//拨打电话
am start -a android.intent.action.CALL -d tel:10086
//打开网站www.baidu.com
am start -a android.intent.action.VIEW -d http://www.baidu.com
//启动Activity
am start [options] <INTENT>
am start -n 包(package)名/包名.活动(activity)名称
am start -n com.yoshin.test/.MainActivity
//启动Activity,携带参数。包名为com.yoshin.test,主Activity为.MainActivity,且extra数据以”key”为key, “value”为value。
am start -n com.yoshin.test/.MainActivity -es key value
//获取当前设备屏幕聚焦app,拿到包名
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
//强制关闭对应包名app
adb shell am force-stop app包名
//发送广播
am broadcast <ACTION>
am broadcas <ACTION> --es myaction <EXTRA>
//启动Service
am startService <ACTION>
//停止Service
am stopservice <INTENT>
//杀指定后台进程
am kill <PACKAGE>
//杀所有后台进程
am kill -all
//强杀进程,作用相当于退出,适用于卡死
am force -stop <PACKAGE>
//系统卡住
am hang
//重启
am restart
或者 am reboot
下面这几个命令没有使用过:
//创建bugreport
am bug -report
//进程pid的堆信息输出到file
am dumpheap <pid> <file>
//收紧进程的内存
am send-trim-memory <pid><level>
//监控
am monitor
[options] 参数讲解
-D: 允许调试功能
-W: 等待app启动完成
-R : 重复启动Activity COUNT次
-S: 启动activity之前,先调用forceStopPackage()方法强制停止app.
–opengl-trace: 运行获取OpenGL函数的trace
–user | current: 指定用户来运行App,默认为当前用户。
–start-profiler : 启动profiler,并将结果发送到 ;
-P : 类似 –start-profiler,不同的是当app进入idle状态,则停止profiling
–sampling INTERVAL: 设置profiler 取样时间间隔,单位ms;
[intent-常用] 参数讲解
常用参数
-a : 指定Intent action, 实现原理Intent.setAction();
-n : 指定组件名,格式为{包名}/.{主Activity名},实现原理Intent.setComponent();
-d : 指定Intent data URI
-t : 指定Intent MIME Type
-c [-c ] …]:指定Intent category,实现原理Intent.addCategory()
-p : 指定包名,实现原理Intent.setPackage();
-f : 添加flags,实现原理Intent.setFlags(int ),紧接着的参数必须是int型;
[intent-Extra] 参数讲解
参数与类型一一对应:
基本类型
参数 -e/-es -esn -ez -ei -el -ef -eu -ecn
类型 String (String)null boolean int long float uri component
数组类型
参数 -esa -eia -ela -efa
数组类型 String[] int[] long[] float[]
ArrayList类型
参数 -esal -eial -elal -efal
List类型 String int long float
[intent-Flags] 参数讲解
[--grant-read-uri-permission] [--grant-write-uri-permission]
[--grant-persistable-uri-permission] [--grant-prefix-uri-permission]
[--debug-log-resolution]
[--exclude-stopped-packages] [--include-stopped-packages]
[--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] [--activity-clear-task]
[--activity-task-on-home]
[--receiver-registered-only] [--receiver-replace-pending]
例如,发送action=”broadcast.demo”的广播,并且对于forceStopPackage()的应用不允许接收该广播,命令如下:
am broadcast -a broadcast.demo --exclude-stopped-packages