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

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

【安装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文件的内容。

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android " package="net.xiashou.android"> <application android:icon="@drawable/icon"> <activity android:name=".HelloAndroid" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

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

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

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

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

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

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android " package="net.xiashou.android"> <application android:icon="@drawable/icon"> <activity android:name=".HelloAndroid" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </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目录内的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值