当前位置: 移动技术网 > 移动技术>移动开发>Android > Android中使用am命令实现在命令行启动程序详解

Android中使用am命令实现在命令行启动程序详解

2019年07月24日  | 移动技术网移动技术  | 我要评论

在android中,除了从界面上启动程序之外,还可以从命令行启动程序,使用的是命令行工具am.

复制代码 代码如下:

usage: am [subcommand] [options]

    start an activity: am start [-d]
        -d: enable debugging

    send a broadcast intent: am broadcast

    start an instrumentation: am instrument [flags]
        -r: print raw results (otherwise decode report_key_streamresult)
        -e : set argument to
        -p : write profiling data to
        -w: wait for instrumentation to finish before returning

    start profiling: am profile start
    stop profiling: am profile stop

    specifications include these flags:
        [-a ] [-d ] [-t ]
        [-c [-c ] ...]
        [-e|--es ...]
        [--ez ...]
        [-e|--ei ...]
        [-n ] [-f ] []


启动的方法为
复制代码 代码如下:

# am start -n 包(package)名/活动(activity)全路径

查看包中每个activity的全路径的方法:
1、安装并启动“固件工具箱”
2、进入“app manager”,显示系统中所有安装程序,长按想通过命令行启动的程序。
3、弹出的窗口中选择"advanced freeze",该程序所有的activity就会全部显示出来
activity有两种显示格式,一种直接显示全路径,另一种在括号里显示相对路径,相对路径加上包名即是全路径。

几个启动指定程序activity的例子
music 和 video(音乐和视频)的启动方法为:

复制代码 代码如下:

# 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

camera(照相机)的启动方法为:
复制代码 代码如下:

# am start -n com.android.camera/com.android.camera.camera

browser(浏览器)的启动方法为:
复制代码 代码如下:

# am start -n com.android.browser/com.android.browser.browseractivity

启动浏览器 :
复制代码 代码如下:

am start -a android.intent.action.view -d 

拨打电话 :
复制代码 代码如下:

am start -a android.intent.action.call -d tel:10086

启动 google map 直接定位到北京 :
复制代码 代码如下:

am start -a android.intent.action.view geo:0,0?q=beijing

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网