adb install

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

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

 

[html]  view plain copy print ?
 
  1. adb -help  

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

 

 

[html]  view plain copy print ?
 
  1. adb install **  

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

 

 

[html]  view plain copy print ?
 
  1. adb install [-l] [-r] [-s] <file> - push this package file to the device and install it  
  2.                                  ('-l' means forward-lock the app)  
  3.                                  ('-r' means reinstall the app, keeping its data)  
  4.                                  ('-s' means install on SD card instead of internal storage)  

如果你的手机或者模拟器已经安装了某个 apk,如 my.apk

那么你没有卸载 my.apk 的话,(命令行操作)再次安装该 apk 的话,会包如下错误:

 

 

[html]  view plain copy print ?
 
  1. 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 源码中寻找一些蛛丝马迹、、、、、、

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

 

[html]  view plain copy print ?
 
  1. /**  
  2.  * Class for retrieving various kinds of information related to the application  
  3.  * packages that are currently installed on the device.  
  4.  *  
  5.  * You can find this class through {@link Context#getPackageManager}.  
  6.  */  
  7. public abstract class PackageManager   

PackageManager 主要是用于获得安装在设备上应用的各种信息。

看一个常量和一个方法,定义如下:

 

 

[html]  view plain copy print ?
 
  1. /**  
  2.  * Flag parameter for {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} to  
  3.  * indicate that this package should be installed as forward locked, i.e. only the app itself  
  4.  * should have access to its code and non-resource assets.  
  5.  * @hide  
  6.  */  
  7. public static final int INSTALL_FORWARD_LOCK = 0x00000001;  
[html]  view plain copy print ?
 
  1. /**  
  2.  * @hide  
  3.  *   
  4.  * Install a package. Since this may take a little while, the result will  
  5.  * be posted back to the given observer.  An installation will fail if the calling context  
  6.  * lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the  
  7.  * package named in the package file's manifest is already installed, or if there's no space  
  8.  * available on the device.  
  9.  *  
  10.  * @param packageURI The location of the package file to install.  This can be a 'file:' or a  
  11.  * 'content:' URI.  
  12.  * @param observer An observer callback to get notified when the package installation is  
  13.  * complete. {@link IPackageInstallObserver#packageInstalled(String, int)} will be  
  14.  * called when that happens.  observer may be null to indicate that no callback is desired.  
  15.  * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},  
  16.  * {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.  
  17.  * @param installerPackageName Optional package name of the application that is performing the  
  18.  * installation. This identifies which market the package came from.  
  19.  */  
  20. public abstract void installPackage(  
  21.         Uri packageURI, IPackageInstallObserver observer, int flags,  
  22.         String installerPackageName);  
[html]  view plain copy print ?
 
  1.   

可以看出:

INSTALL_FORWARD_LOCK 常量主要是用来保护自己的 app,installPackage 方法的参数 int flags 可以是 INSTALL_FORWARD_LOCK。

 

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

 

好了,目前为止,-l 参数是用来保护自己的 app,即 forward-locked(正向锁定)!

 

不过,平时安装测试 app,很少使用该参数!

 

 

 

http://blog.csdn.net/veryitman/article/details/6608802

猜你喜欢

转载自oywl2008.iteye.com/blog/1990602
今日推荐