Android adb shell启动应用程序的方法

xiaoxiao2021-02-28  76

在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
转载请注明原文地址: https://www.6miu.com/read-23529.html

最新回复(0)