在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
url:http://greatverve.cnblogs.com/archive/2012/02/10/android-am.html
adb shell 打開應用程序
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
android開發中遇到的問題彙總【四】
yangyabin2020
2020-06-28 09:22:52
android開發中遇到的問題彙總【三】
yangyabin2020
2020-06-28 09:22:52
include進來的控件無法用layout_alignParentBottom="true"
cao12345cong
2020-06-25 21:39:44
adb shell模擬點擊事件 input
Cod_erL
2020-06-07 23:43:27
關於Chronometer(計時器)暫停的問題
丶不二
2020-02-24 23:45:07
Android Studio使用SVN報錯:XXX不是工作副本(XXX is not working copy)
丶不二
2020-02-24 23:45:07
android studio 多版本打包
Cod_erL
2020-02-24 04:42:14
Android應用程序創建熱點以及自動鏈接Wifi,我遇到的問題以及我是怎麼解決的
Cod_erL
2020-02-24 04:42:14
Android app做成 (home)launcher 只是 應用開發非ROM 開發
Cod_erL
2020-02-24 04:42:14
android studion 內存溢出GC
Cod_erL
2020-02-24 04:42:14
android加混淆 方式與坑
Cod_erL
2020-02-24 04:42:14
android Xutile ,Voller 對比
Cod_erL
2020-02-24 04:42:14
android INSTALL_FAILED_CONFLICTING_PROVIDER
Cod_erL
2020-02-24 04:42:03
android開發中遇到的問題【一】
yangyabin2020
2020-02-22 04:12:06
24小時熱門文章