如何让自己的Android应用程序支持安装到SD卡呢?

下面给出官方的解决方案

App Install Location

Quickview

  • You can allow your application to install on the device's external storage.
  • Some types of applications should not allow installation on the external storage.
  • Installing on the external storage is ideal for large applications that are not tightly integrated with the system (most commonly, games).

In this document

  1. Backward Compatibility
  2. Applications That Should NOT Install on External Storage
  3. Applications That Should Install on External Storage

See also

  1. <manifest>

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 the android: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 the android:installLocation attribute in the <manifest> element, with a value of either "preferExternal" or "auto". For example:

        
  1. <manifestxmlns:android="http://schemas.android.com/apk/res/android"
  2. android:installLocation="preferExternal"
  3. ...>

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.

Warning: When the user enables USB mass storage to share files with a computer or unmounts the SD card via the system settings, the external storage is unmounted from the device and all applications running on the external storage are immediately killed.

更多相关文章

  1. Android开发错误——Android Studio中遇到过的错误问题与解决方
  2. 最新版 Android SDK 无法获取SDK包 的解决方案
  3. 最全的PHP开发Android应用程序
  4. 用Eclipse开发Android应用程序(3): 开发第一个Android应用程序He
  5. android中怎样将自己的应用程序的签名改为系统签名一样
  6. 使用PHP开发Android应用程序技术介绍
  7. Android处理屏幕旋转时的解决方案

随机推荐

  1. Mysql主从复制作用和工作原理详解
  2. Mysql时间轴数据 获取同一天数据的前三条
  3. mybatis 实现 SQL 查询拦截修改详解
  4. MySQL 整表加密解决方案 keyring_file详
  5. sqlite3迁移mysql可能遇到的问题集合
  6. 关于MySQL性能调优你必须了解的15个重要
  7. MySql减少内存占用的方法详解
  8. 这种sql写法真的会导致索引失效吗
  9. mysql聚簇索引的页分裂原理实例分析
  10. 分析一条sql的性能的标准总结