在Android模拟器上安装和卸载APK包

来源:互联网 发布:ip 网络层 编辑:程序博客网 时间:2024/04/29 08:25

 

【安装APK】
    安装APK当然首先是要有模拟器,和要安装的APK包。

    首先,将模拟器执行起来,直到正式进入系统。
    接下来,打开一个cmd窗口,路径切换到模拟器目录下的tools目录。
    输入:adb install 你要安装的apk文件的路径。

    如果看到一行类显示传输速度的文字,那说明安装成功了。如下:
    C:/Documents and Settings/Administrator>cd D:/andriod/tools

    C:/Documents and Settings/Administrator>d:

    D:/android/tools>adb install c:/NetScramble_1.1.apk 100 KB/s (0 bytes in 164464.001s)

    回到Android模拟器的界面,我本来以为可以看到刚刚安装的APK程序图标,结果,却根本没有...后来研究了一下,发现这根APK包自身有关。使用 自己编写的HelloAndroid安装,图标就可以显示在桌面上,而NetScramble_1.1.apk安装后却显示不出来。具体原因是来自于 AndroidManifest.xml文件的内容。

[xhtml] view plaincopyprint?
  1. <?xmlversion="1.0"encoding="utf-8"?> 
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android " package="net.xiashou.android"> 
  3.     <applicationandroid:icon="@drawable/icon"> 
  4.     <activityandroid:name=".HelloAndroid"android:label="@string/app_name"> 
  5.         <intent-filter> 
  6.             <actionandroid:name="android.intent.action.MAIN"/> 
  7.             <categoryandroid:name="android.intent.category.LAUNCHER"/> 
  8.        </intent-filter> 
  9.     </activity> 
  10.     </application> 
  11. </manifest> 

    xml文件中,红色一行是表示这个apk属于哪个归类里,如果不正确的填写这个信息,Launcher将不会将其显示在桌面上,因为它会认为这个应用部署以自己的归类。

    那么,是不是我们就无法执行缺失了category的apk了呢?

    后来,在一个老外的blog上,查到了方法:在shell内使用am来加载android应用

   

[xhtml] view plaincopyprint?
  1. usage: am [start|instrument] 
  2.        am start [-a <ACTION>] [-d<DATA_URI>] [-t<MIME_TYPE>] [-c<CATEGORY> [-c<CATEGORY>] ...]  
  3.                 [-e <EXTRA_KEY><EXTRA_VALUE> [-e<EXTRA_KEY><EXTRA_VALUE> ...] [-n<COMPONENT>] [-D] [<URI>
  4.        am instrument [-e <ARG_NAME><ARG_VALUE>] [-p<PROF_FILE>] [-w]<COMPONENT> 

    比如启动一个manifest为如下内容的apk

   

[xhtml] view plaincopyprint?
  1. <?xmlversion="1.0"encoding="utf-8"?> 
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android "package="net.xiashou.android"> 
  3.      <applicationandroid:icon="@drawable/icon"> 
  4.      <activityandroid:name=".HelloAndroid"android:label="@string/app_name"> 
  5.           <intent-filter> 
  6.               <actionandroid:name="android.intent.action.MAIN"/> 
  7.               <categoryandroid:name="android.intent.category.LAUNCHER"/> 
  8.           </intent-filter> 
  9.     </activity> 
  10.     </application> 
  11. </manifest> 

    使用的指令为:

    am start -n net.xiashou.android/net.xiashou.android.HelloAndroid

    还有一些很有用处的用法

    直接启动浏览器打开一个网址 # am start -a android.intent.action.VIEW -d http://snowyrock.spaces.live.com

    拨打电话 # am start -a android.intent.action.CALL -d tel:10086 启动google map直接定位在天津 # am start -a android.intent.action.VIEW  geo:0,0?q=tianjin

    am很可能将来成为第三方lancher的基础。

【卸装APK】

    与安装类似的,卸妆是利用adb执行一个卸妆指令:

    D:/android/tools>adb shell rm data/app/NetScramble_1.1.apk

    这里,也可以看出,Android系统是将第三方应用放在data/app目录内的。

0 0
原创粉丝点击