博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Android AM命令

Posted on 2013-06-12 00:07  泡泡糖  阅读(904)  评论(0编辑  收藏  举报

Android里面可以通过终端使用AM命令启动某个指定的Activity。工作中因为新开发的机器需要进行屏幕坐标校准,机器因为还没调试好,每次坐标校准都没有出现,机器使用不了,只能通过终端调用坐标校准的Activity启动。

 

例如启动 coordinate.apk的主activity

am start -n com.apical.apicalcoordinate/com.apical.apicalcoordinate.coordinateActivity

其中com.apical.apicalcoordinate是应用Activity所在的包名。

 

usage: am [subcommand] [options]

    start an Activity: am start [-D] <INTENT>
        -D: enable debugging

    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

    <INTENT> specifications include these flags:
        [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
        [-c <CATEGORY> [-c <CATEGORY>] ...]
        [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
        [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
        [-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
        [-n <COMPONENT>] [-f <FLAGS>] [<URI>]

启动的方法为

# am start -n 包(package)名/包名.活动(activity)名称

启动的方法可以从每个应用的AndroidManifest.xml的文件中得到

 

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  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=beijing