android开发分享Android中使用am命令实现在命令行启动程序详解

在android中,除了从界面上启动程序之外,还可以从命令行启动程序,使用的是命令行工具am. 复制代码 代码如下: usage: am [subcommand] [

在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有两种显示格式,一种直接显示全路径,另一种在括号里显示相对路径,相对路径加上包名即是全路径。

上述就是android开发分享Android中使用am命令实现在命令行启动程序详解的全部内容,如果对大家有所用处且需要了解更多关于Android学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

几个启动指定程序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

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/addevelopment/940948.html

(0)
上一篇 2021年11月14日
下一篇 2021年11月14日

精彩推荐