---
title: " Android开发片段–命令行安装，卸载，启动，程序（AM,PM）"
author: "04023129"
date: "2011-12-15T17:15:52Z"
tags: []
categories: ["移动开发"]
slug: "android-am-pm"
draft: false
lastmod: "2011-12-15T17:15:52Z"
id: 1312478
url: "https://zzh.iteye.com/blog/1312478"
---

[Android AM命令行启动程序的方法](http://blog.csdn.net/sunrock/article/details/5675067 "Android AM命令行启动程序的方法")

usage: am \[subcommand] \[options]

    start an Activity: am start \[-D] &lt;INTENT&gt;  
        -D: enable debugging

    send a broadcast Intent: am broadcast &lt;INTENT&gt;

    start an Instrumentation: am instrument \[flags] &lt;COMPONENT&gt;  
        -r: print raw results (otherwise decode REPORT\_KEY\_STREAMRESULT)  
        -e &lt;NAME&gt; &lt;VALUE&gt;: set argument &lt;NAME&gt; to &lt;VALUE&gt;  
        -p &lt;FILE&gt;: write profiling data to &lt;FILE&gt;  
        -w: wait for instrumentation to finish before returning

    start profiling: am profile &lt;PROCESS&gt; start &lt;FILE&gt;  
    stop profiling: am profile &lt;PROCESS&gt; stop

    &lt;INTENT&gt; specifications include these flags:  
        \[-a &lt;ACTION&gt;] \[-d &lt;DATA\_URI&gt;] \[-t &lt;MIME\_TYPE&gt;]  
        \[-c &lt;CATEGORY&gt; \[-c &lt;CATEGORY&gt;] ...]  
        \[-e|--es &lt;EXTRA\_KEY&gt; &lt;EXTRA\_STRING\_VALUE&gt; ...]  
        \[--ez &lt;EXTRA\_KEY&gt; &lt;EXTRA\_BOOLEAN\_VALUE&gt; ...]  
        \[-e|--ei &lt;EXTRA\_KEY&gt; &lt;EXTRA\_INT\_VALUE&gt; ...]  
        \[-n &lt;COMPONENT&gt;] \[-f &lt;FLAGS&gt;] \[&lt;URI&gt;]

启动的方法为

\# 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/](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

 

[Android中pm命令用法](http://blog.csdn.net/wufenglong/article/details/5778560 "Android中pm命令用法")

pm命令的具体用法如下：

usage: pm \[list|path|install|uninstall]   
       pm list packages \[-f]   
       pm list permission-groups   
       pm list permissions \[-g] \[-f] \[-d] \[-u] \[GROUP]   
       pm list instrumentation \[-f] \[TARGET-PACKAGE]   
       pm path PACKAGE   
       pm install \[-l] \[-r] PATH   
       pm uninstall \[-k] PACKAGE   
       pm enable PACKAGE\_OR\_COMPONENT   
       pm disable PACKAGE\_OR\_COMPONENT

The list packages command prints all packages.  Use   
the -f option to see their associated file.

The list permission-groups command prints all known   
permission groups.

The list permissions command prints all known   
permissions, optionally only those in GROUP.  Use   
the -g option to organize by group.  Use   
the -f option to print all information.  Use   
the -s option for a short summary.  Use   
the -d option to only list dangerous permissions.  Use   
the -u option to list only the permissions users will see.

The list instrumentation command prints all instrumentations,   
or only those that target a specified package.  Use the -f option   
to see their associated file.

The path command prints the path to the .apk of a package.

The install command installs a package to the system.  Use   
the -l option to install the package with FORWARD\_LOCK. Use   
the -r option to reinstall an exisiting app, keeping its data.

The uninstall command removes a package from the system. Use   
the -k option to keep the data and cache directories around   
after the package removal.