zoukankan      html  css  js  c++  java
  • (转)Android 使用 adb shell 命令行启动应用

    原文:http://blog.chinaunix.net/uid-26997997-id-3350449.html

    在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 ] []

    启动的方法为

          $ adb shell
          $ am start -n {包(package)名}/{包名}.{活动(activity)名称}

    程序的入口类可以从每个应用的AndroidManifest.xml的文件中得到,以计算器(calculator)为例,它的

    package="com.android.calculator2" …>…

    由此计算器(calculator)的启动方法为:

    # am start -n com.android.calculator2/com.android.calculator2.Calculator

    对于HelloActivity这个示例工程,AndroidManifest.xml如下所示:

    package="com.example.android.helloactivity" …>

    由此它的启动方法为:

    # am start -n com.example.android.helloactivity/com.example.android.helloactivity.HelloActivity

    其他的一些应用启动命令,如下所示:

    calendar(日历)的启动方法为:

    # am start -n com.android.calendar/com.android.calendar.LaunchActivity

    AlarmClock(闹钟)的启动方法为:

    # am start -n com.android.alarmclock/com.android.alarmclock.AlarmClock

    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

      一般情况希望,一个Android应用对应一个工程。值得注意的是,有一些工程具有多个活动(activity),而有一些应用使用一个工程。例如:在Android界面中,Music和Video是两个应用,但是它们使用的都是packages/apps/Music这一个工程。而在这个工程的AndroidManifest.xml文件中,有包含了不同的活动(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  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

  • 相关阅读:
    NodeJS学习笔记 (7)网络服务-http-client(ok)
    NodeJS学习笔记 (6)网络服务-http-res(ok)
    NodeJS学习笔记 (5)网络服务-http-req(ok)
    NodeJS学习笔记 (4)网络服务-http(ok)
    NodeJS学习笔记 (3)域名解析-dns(ok)
    NodeJS学习笔记 (2)文件系统操作-fs(ok)
    NodeJS学习笔记 (1)资源压缩-zlib(ok)
    indexedDB介绍
    React diff机制(介绍虚拟DOM的机制)
    区间dp总结
  • 原文地址:https://www.cnblogs.com/ren-gh/p/4018560.html
Copyright © 2011-2022 走看看