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. C++primer 练习12.27

    // 12_27.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  2. 学习Webservice测试

    2014-04-01 可用Myeclipse10自带工具生成客户端, 也可用CXF生成,注意,不要用CXF3.0.0milestone,该版本不能生成,请用CXF2.2.8 2015-01-12 下载 ...

  3. 部署windows服务

    (1) cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319(2) InstallUtil.exe D:\SVN\zhongchao\开发\WeiXin ...

  4. testng参数化方法:Parameters和DataProvider

    Parameters注解在测试方法上指定参数列表,然后在测试方法中声明对应的形参,形参与参数列表一一对应,但名字可以不同,如下所示: public class Test1 { @Parameters( ...

  5. [实战经验]Macbook pro 苹果系统换window系统

    1.       Macbook的window软件驱动备份 通过Boot Camp助手进行window支持苹果驱动下载 2.       拆机把SSD固态硬盘放在主盘位置,把苹果的机械盘放在光驱位置 ...

  6. Android开发-API指南-<instrumentation >

    <instrumentation> 英文原文:http://developer.android.com/guide/topics/manifest/instrumentation-elem ...

  7. 使用HTTP协下载文件

    通过发送HTTP请求,下载文件 头文件: #ifndef __HTTP__ #define __HTTP__ #include <stdio.h> #include <stdlib. ...

  8. FindResource函数错误代码:1813-找不到映像文件中指定的资源类型 与LoadResource函数错误代码:1812-指定的映像文件不包含资源区域

    HRSRC WINAPI FindResource( _In_opt_  HMODULE hModule, _In_      LPCTSTR lpName, _In_      LPCTSTR lp ...

  9. QTP操作论坛回复编辑框----webelement

    Set bp=browser("micclass:=browser","index:=0").page("micclass:=page") ...

  10. iOS常用插件

    iOS常用插件总结:http://blog.csdn.net/oik_ios/article/details/50251191http://www.jianshu.com/p/d24eea8b405a ...