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 externalstorage.
  • Installing on the external storage is ideal for large applications that are not tightlyintegrated 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 theexternal storage (for example, the device's SD card). This is an optional feature you can declarefor your application with the android:installLocation manifest attribute. If you donot declare this attribute, your application will be installed on the internal storageonly and it cannot be moved to the external storage.

To allow the system to install your application on the external storage, modify yourmanifest file to include the android: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 theexternal storage, but the system does not guarantee that your application will be installed onthe external storage. If the external storage is full, the system will install it on the internalstorage. The user can also move your application between the two locations.

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

When your application is installed on the external storage:

  • There is no effect on the application performance so longas 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 theinternal device memory.
  • The unique container in which your application is stored is encrypted with a randomlygenerated key that can be decrypted only by the device that originally installed it. Thus, anapplication 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 fileswith a computer or unmounts the SD card via the system settings, the external storage is unmountedfrom the device and all applications running on the external storage are immediately killed.

Backward Compatibility

The ability for your application to install on the external storage is a feature available onlyon devices running API Level 8 (Android 2.2) or greater. Existing applications that were built priorto API Level 8 will always install on the internal storage and cannot be moved to the externalstorage (even on devices with API Level 8). However, if your application is designed to support anAPI Level lower than 8, you can choose to support this feature for devices with API Level 8or greater and still be compatible with devices using an API Level lower than 8.

To allow installation on external storage and remain compatible with versions lower than APILevel 8:

  1. Include the android:installLocation attribute with a value of "auto" or"preferExternal" in the <manifest>element.
  2. Leave your android:minSdkVersion attribute as is (something lessthan "8") and be certain that your application code uses only APIs compatible with thatlevel.
  3. In order to compile your application, change your build target to API Level 8. This isnecessary because older Android libraries don't understand the android:installLocationattribute and will not compile your application when it's present.

When your application is installed on a device with an API Level lower than 8, the android:installLocation attribute is ignored and the application is installed on the internalstorage.

Caution: Although XML markup such as this will be ignored byolder platforms, you must be careful not to use programming APIs introduced in API Level 8while your minSdkVersion is less than "8", unless you perform the work necessary toprovide backward compatibility in your code. For information about buildingbackward compatibility in your application code, see the Backward Compatibilityarticle.

Applications That Should NOT Install on External Storage

When the user enables USB mass storage to share files with their computer (or otherwiseunmounts or removes the external storage), any applicationinstalled on the external storage and currently running is killed. The system effectively becomesunaware of the application until mass storage is disabled and the external storage isremounted on the device. Besides killing the application and making it unavailable to the user,this can break some types of applications in a more serious way. In order for your application toconsistently behave as expected, you should not allow your application to beinstalled on the external storage if it uses any of the following features, due to the citedconsequences when the external storage is unmounted:

Services
Your runningService will be killed and will not be restarted whenexternal storage is remounted. You can, however, register for theACTION_EXTERNAL_APPLICATIONS_AVAILABLE broadcast Intent, which will notifyyour application when applications installed on external storage have become available to thesystem again. At which time, you can restart your Service.
Alarm Services
Your alarms registered withAlarmManager will be cancelled. You mustmanually re-register any alarms when external storage is remounted.
Input Method Engines
Your IME will bereplaced by the default IME. When external storage is remounted, the user can open system settingsto enable your IME again.
Live Wallpapers
Your running Live Wallpaperwill be replaced by the default Live Wallpaper. When external storage is remounted, the user canselect your Live Wallpaper again.
Live Folders
Your Live Folder will beremoved from the home screen. When external storage is remounted, the user can add your Live Folderto the home screen again.
App Widgets
Your App Widget will be removedfrom the home screen. When external storage is remounted, your App Widget willnot beavailable for the user to select until the system resets the home application (usually not until asystem reboot).
Account Managers
Your accounts created withAccountManager will disappear untilexternal storage is remounted.
Sync Adapters
YourAbstractThreadedSyncAdapter and all its sync functionality willnot work until external storage is remounted.
Device Administrators
YourDeviceAdminReceiver and all its admin capabilities willbe disabled, which can have unforeseeable consequences for the device functionality, which maypersist after external storage is remounted.
Broadcast Receivers listening for "boot completed"
The system delivers theACTION_BOOT_COMPLETED broadcastbefore the external storage is mounted to the device. If your application is installed on theexternal storage, it can never receive this broadcast.
Copy Protection
Your application cannot be installed to a device's SD card if it uses Android Market's Copy Protection feature. However, if you use Android Market's Application Licensing instead, your applicationcan be installed to internal or external storage, including SD cards.

If your application uses any of the features listed above, you should not allowyour application to install on external storage. By default, the system will not allow yourapplication to install on the external storage, so you don't need to worry about your existingapplications. However, if you're certain that your application should never be installed on theexternal storage, then you should make this clear by declaring android:installLocation with a value of "internalOnly". Though this does notchange the default behavior, it explicitly states that your application should only be installedon the internal storage and serves as a reminder to you and other developers that this decision hasbeen made.

Applications That Should Install on External Storage

In simple terms, anything that does not use the features listed in the previous sectionare safe when installed on external storage. Large games are more commonly the types ofapplications that should allow installation on external storage, because games don't typicallyprovide additional services when innactive. When external storage becomes unavailable and a gameprocess is killed, there should be no visible effect when the storage becomes available again andthe user restarts the game (assuming that the game properly saved its state during the normalActivity lifecycle).

If your application requires several megabytes for the APK file, you shouldcarefully consider whether to enable the application to install on the external storage so thatusers can preserve space on their internal storage.


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 第一次运行Android(安卓)Studio
  2. android 网络编程 HttpGet类和HttpPost类
  3. android 文件合并打包 Error:Execution f
  4. Android(安卓)Fragment和FragmentActivit
  5. Android(安卓)Sudio 开发环境配置
  6. Android(安卓)GreenDao数据库使用
  7. Android(安卓)Audio Focus的应用(request
  8. Okhttp封装
  9. android html5网页定位
  10. Android(安卓)SDK各个版本API的特性及兼