App Install Location

Source: Internet
Author: User

From API level 8, you can install applications to external storage devices (such as SD cards ). This attribute can be declared in manifest through the android: installLocation attribute. If this attribute is not declared, the application will only be installed in the memory and cannot be moved to an external storage device.
To install an application to an external storage device, you only need to modify the manifest file and add the android: installLocation attribute to the manifest element. The attribute value is preferExternal or auto. For example:

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


If this attribute is set to "preferExternal", the user requires the application to be installed on an external storage device, but the system does not guarantee that the application is actually installed on an external storage device. If the space of the external storage device is full, the system will still install the application in the memory. You can also move the application between two locations.
If this property value is set to "auto", it indicates that the application may be installed on an external storage device, but the user has no special requirements on the installation location. The system determines where the application is installed based on multiple factors. You can also move the application between two locations.
When an application is installed on an external storage device:
As long as the external storage device is mounted on the device, the performance of the application will not be affected.
The. apk file is stored on an external storage device, but all private user data, databases, optimized. dex files, and extracted local code are stored in the device's memory.
The unique container that saves the application is encrypted with a random key. This key can only be decrypted by the device that initially installed the program. Therefore, applications installed on SD cards can only run on a fixed device.
You can use system settings to move applications to the memory.
Note: When a user uses a USB large-capacity memory to share files with a computer, or uses the system settings to uninstall the SD card, the external storage device will be detached from this device, all applications running on the external storage device will be immediately disabled.
Backward compatibility
Applications can be installed on external storage devices as API level 8 (android 2.2) and above. Previously, applications can only be installed in memory and cannot be moved to external storage devices (even if the device is at API level 8 ). However, if the application is designed to support devices lower than the API level 8, you can choose whether to support this feature on devices with API level 8 or above, it is also compatible with devices that use API level 8 or lower.
To install a program on an external storage device and be compatible with a version earlier than API level 8, you must:
1. Add the android: installLocation attribute to the manifest element and set the attribute value to "auto" or "preferExternal ".
2. Keep the attributes of android: minSdkVersion unchanged (less than a value of 8) to ensure that the application code is compatible with this level.
3. In order to compile the program, set the generation target to API level 8. This step is necessary because the old android library does not recognize the android: installLocation attribute. When this attribute exists, the application cannot be compiled.
When the application is installed on a device lower than the API level 8, the android: installLocation attribute is ignored and the application is installed in the memory.
Note: Although XML tags like this are ignored on old platforms, when android: minSdkVersion is earlier than 8, during programming, be sure to avoid using the recommended method of API level 8 unless backward compatibility is provided in the Code.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.