Android AM命令及使用

Android AM命令及使用

 

Android系統可以通過終端使用AM命令啟動某個指定的Activity。在具體應用中可以通過AM命令來達到啟動指定Activity的目的。

 

例如啟動 Camera.apk的主activity

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

其中com.android.camera是應用Activity所在的包名,com.android.camera.Camera是指定要啟動的Activity。

 

————————–

am 命令使用說明:

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的文件中得到

 

————————–

am命令在系統中的具體應用:

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  https://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

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *