Beginning with API Level 8, you can allow your application to be installed on the external storage (for example, the device's SD card). This is an optional feature you can declare for your application with theandroid:installLocation manifest attribute. If you do not declare this attribute, your application will be installed on the internal storage only and it cannot be moved to the external storage.

To allow the system to install your application on the external storage, modify your manifest file to include theandroid:installLocation attribute in the <manifest> element, with a value of either "preferExternal" or "auto". For example:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="preferExternal"
... >

If you declare "preferExternal", you request that your application be installed on the external storage, but the system does not guarantee that your application will be installed on the external storage. If the external storage is full, the system will install it on the internal storage. The user can also move your application between the two locations.

If you declare "auto", you indicate that your application may be installed on the external storage, but you don't have a preference of install location. The system will decide where to install your application based on several factors. The user can also move your application between the two locations.

When your application is installed on the external storage:

  • There is no effect on the application performance so long as the external storage is mounted on the device.
  • The .apk file is saved on the external storage, but all private user data, databases, optimized.dex files, and extracted native code are saved on the internal device memory.
  • The unique container in which your application is stored is encrypted with a randomly generated key that can be decrypted only by the device that originally installed it. Thus, an application installed on an SD card works for only one device.
  • The user can move your application to the internal storage through the system settings.

拣重点说一下这篇文章。这篇技术文档主要核心内容是讲,从Android API Level 8开始,Android APP开发者可以在自己的APP中编程设置APP安装的位置:安装在外置/外部扩展存储卡上(比如设备上用户插入的扩展SD卡)。这一特色的实现,只需在Android的manifest设置:android:installLocation 的属性值。如果开发者没有设置这一值,那么,Android系统将会把你的APP安装在内置/内部存储中并且不允许被移动到外部/外置存储。

因此,为了能让系统把你的APP安装在外部/外置扩展存储中,你需要在manifest修改android:installLocation 的属性值,把android:installLocation 设置为"preferExternal" o或者"auto"。

如果你声明了"preferExternal"(android:installLocation= "preferExternal",),意即为要求系统将你的APP安装在外部/外置扩展存储,但是系统并一定总是这么做。假设外部/外置存储已满,系统仍然会将你的APP安装在内部/内置存储。当用户安装了你的APP后,用户可以把你的APP在外部/外置和内部/内置存储之间来回移动。

如果你声明了 "auto"(android:installLocation ="auto"),你意图让系统把你的APP安装在外部/外置存储,但是你没有对安装位置有特别偏好。所以最终还是由系统综合考量若干因素然后决定你的APP安装的位置,同时,用户仍然可以自主的在外部和内部存储之间来回移动你的APP。

更多其他详细细节内容,请看原始谷歌官方文档,文档链接地址:http://developer.android.com/guide/topics/data/install-location.html#Compatiblity

本文转载与于:http://blog.csdn.net/zhangphil/article/details/46534175

(转)Android如何编程设置APP安装位置(外部存储或内部存储)?的更多相关文章

  1. Android内存解析(二)— 详解内存,内部存储和外部存储

    总述 觉得十分有必要搞清楚内存,内部存储和外部存储的区别,还有我们在开发中真正将数据存在了手机的哪儿. 先提一个问题:手机设置的应用管理中,每个App下都有清除数据和清除缓存,清除的分别是哪里的数据? ...

  2. android数据储存之应用安装位置

    原文地址:http://developer.android.com/guide/topics/data/install-location.html#Compatiblity 从API8開始,你能够将你 ...

  3. app安装位置声明

    AndroidManifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" ...

  4. Android数据存储之内部存储、外部存储

    首先来介绍下什么是内部存储? 在Android平台下,有着自己独立的数据存储规则,在windows平台下,应用程序能够自由的或者在特定的訪问权限基础上訪问或改动其它应用程序下的文件资源. 可是在And ...

  5. [Android教程]EditText设置/隐藏光标位置、选中文本和获取/清除焦点

      有时候需要让光标显示在EditText的指定位置或者选中某些文本.同样,为了方便用户输入以提升用户体验,可能需要使EditText获得或失去焦点. 1. 设置光标到指定位置 EditText et ...

  6. Android数据存储-读取内部存储空间数据

    内部存储空间的默认位置 data/data/应用名称 写数据,获取FileOutPutStream的方式 1.直接写死路径的方式 FileOutputStream fos = new FileOutp ...

  7. 初探Lambda表达式/Java多核编程【0】从外部迭代到内部迭代

    开篇 放假前从学校图书馆中借来一本书,Oracle官方的<精通Lambda表达式:Java多核编程>. 假期已过大半才想起来还没翻上几页,在此先推荐给大家. 此书内容及其简洁干练,如果你对 ...

  8. Android应用程序的安装位置

    Android应用程序的默认安装位置以及是否可移动取决于开发者在其AndroidManifest.xml中的设置:   <manifestxmlns:android="http://s ...

  9. Android中的内存储、外存储概念、文件操作与PC端的有些不同

    其实安卓文件的操作和java在pc环境下的操作并无二致,之所以需要单独讲解是因为安卓系统提供了不同于pc的访问文件系统根路径的api,同时对一个应用的私有文件做了统一的管理.初学者在这部分感到很容易混 ...

随机推荐

  1. reverse list

    public void reverse (){ Node end =null,p,q; p=head; //p代表当前节点,end代表翻转后p后面的,q代表翻转前p后面的 while(p!=null) ...

  2. MongoDB条件查询

    1.查询集合中的所有记录 db.users.find() { "_id" : ObjectId("528b1173613e3289197a6486"), &qu ...

  3. keypress

    onKeyUp="keypress2(this,140)" onblur="keypress2(this,140)"<span>你还可以输入140个 ...

  4. cocos2d-x中false,setSwallowTouches,stopPropagation的区别

    研究到cocos2d-x触摸这一块了,3.0和2.0相比已经有了很大的不同,使用更加方便和容易理解了. 直接进入正题,解释下,标题中3个用法的区别 通常来说,应用程序中更多使用的是单点触摸,为了简化单 ...

  5. 为网站加入Drupal星球制作RSS订阅源

    目前中文 Drupal 星球的版块还未成立,但大家的积极性挺高,不少站长都已经调整好自己的网站,生成了可供Drupal Planet 使用的RSS订阅源. 如果你也想让网站做好准备,可以不必再花上不少 ...

  6. Change screensaver through registry

    If you wanna change the screensaver, you can update registry as follows{autoit script}: RegWrite(&qu ...

  7. 二模09day1解题报告

    T1.词编码(word) 给出一些原长为n的01串经过变化后的串求原串.原串的特点是:各个1的位置号和%(n+1)==0 变法(只取其一): 改一个0为1 删一个 加一个 不变. 其中2优先考虑位置靠 ...

  8. oracle:触发器,自治事务 trigger

    create or replace trigger TRI_FC83_INSERT before insert ON FC83 FOR EACH ROW declare PRAGMA AUTONOMO ...

  9. ionic goto other page or alert

    有时候需要 调试,这是就需要alert 的...可惜的是我不会angular  所以记录一下 .controller('mainctr', function($scope, $window) { $w ...

  10. 【Linux】基于Bind_DLZ和MySQL数据的DNS搭建

    参考:http://www.linuxfromscratch.org/blfs/view/cvs/server/bind.html 参考:http://bind-dlz.sourceforge.net ...