安装 apk,居然意外收获

本文详细解析了Android调试桥(ADB)的常用命令,特别是install命令的各个选项,包括-l(forward-lock)、-r(reinstall)和-s(install on SD card)。通过实际案例解释了这些选项在不同场景下的具体应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

个人比较喜欢命令行操作,特别是在 android开发的时候,方便!

在终端敲入命令,会出现关于adb工具的使用帮助。

adb -help安装 apk,一般都是使用命令:

adb install **在 adb -help 可以看到如下帮助:

adb install [-l] [-r] [-s] <file> - push this package file to the device and install it ('-l' means forward-lock the app) ('-r' means reinstall the app, keeping its data) ('-s' means install on SD card instead of internal storage)如果你的手机或者模拟器已经安装了某个 apk,如 my.apk,那么你没有卸载 my.apk 的话,(命令行操作)再次安装该 apk 的话,会包如下错误:

Failure [INSTALL_FAILED_ALREADY_EXISTS]

-r 参数表示重新安装 apk,所以加上这个参数就不会有上述错误。

-s 参数表示安装 apk 到 SDcard,好了。郁闷的时刻到来!-l 参数什么意思?

自己做了很多测试,也不是很明白。最后在 sdk api上找到答案。感谢:sdk-path/docs/guide/appendix/market-filters.html

看下面这张截图,也许回得到点启发。大致意思是在发布 apk 到 android market上时,可以设置相关标志位来保护你的 app。

那么,再从 PackageManager.java 源码中寻找一些蛛丝马迹、、、、、、

该类是一个抽象类,声明如下:

/** * Class for retrieving various kinds of information related to the application * packages that are currently installed on the device. * * You can find this class through {@link Context#getPackageManager}. */ public abstract class PackageManager PackageManager 主要是用于获得安装在设备上应用的各种信息。看一个常量和一个方法,定义如下:

/** * Flag parameter for {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} to * indicate that this package should be installed as forward locked, i.e. only the app itself * should have access to its code and non-resource assets. * @hide */ public static final int INSTALL_FORWARD_LOCK = 0x00000001; /** * @hide * * Install a package. Since this may take a little while, the result will * be posted back to the given observer. An installation will fail if the calling context * lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the * package named in the package file's manifest is already installed, or if there's no space * available on the device. * * @param packageURI The location of the package file to install. This can be a 'file:' or a * 'content:' URI. * @param observer An observer callback to get notified when the package installation is * complete. {@link IPackageInstallObserver#packageInstalled(String, int)} will be * called when that happens. observer may be null to indicate that no callback is desired. * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK}, * {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}. * @param installerPackageName Optional package name of the application that is performing the * installation. This identifies which market the package came from. */ public abstract void installPackage( Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName); 可以看出,INSTALL_FORWARD_LOCK 常量主要是用来保护自己的 app,installPackage方法的参数 int flags 可以是INSTALL_FORWARD_LOCK。

注意:在 android1.5 源码中,INSTALL_FORWARD_LOCK 常量是ORWARD_LOCK_PACKAGE。

好了,目前为止,-l 参数是用来保护自己的 app,即forward-locked(正向锁定)!平时安装测试 app,该参数没什么作用!




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值