adb啓動程序命令:adb shell am start

在Android中,除了從界面上啓動程序以外,還能夠從命令行啓動程序,使用的是命令行工具am.

啓動的方法爲android

adb shell
      # am start -n {包(package)名}/{包名}.{活動(activity)名稱}shell

程序的入口類能夠從每一個應用的AndroidManifest.xml的文件中獲得,以計算器(calculator)爲例,它的瀏覽器

 

<manifest xmlns:android="http://schemas.android.com/apk/res/android" …app

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

 

 

 

 

 

 

 

由此計算器(calculator)的啓動方法爲:# am start -n com.android.calculator2/com.android.calculator2.Calculator工具

對於HelloActivity這個示例工程,AndroidManifest.xml以下所示:google

 

<manifest …spa

package="com.example.android.helloactivity" …>命令行

 

 

 

 

 

 

 

 

 

由此它的啓動方法爲:debug

# 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)。
 

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

相關文章
相關標籤/搜索