Starting with API Level 8 (Android 2.2), you can install your application on external storage (for example, the device's SD card). You can declare the Android:installlocation property in the application's manifest file to use this optional feature. If you do not declare this attribute, your application can only be installed in internal storage and cannot be moved to external storage.
Allow the system to install your application on the external storage, you need to modify your manifest file. Under the <manifest> tab, add the Android:installlocation property and set the value to "preferexternal" or "Auto". For example:
<manifest xmlns:android= "http://schemas.android.com/apk/res/android" android:installlocation= " Preferexternal "... >
If you declare "preferexternal", this means that the request system installs your application to external storage, but the system does not guarantee that your application will be installed on external storage. If the external storage space is full, the system installs the application on the internal storage. Users can also move your application between internal and external storage.
If you declare "Auto", this indicates that your application can be installed on external storage, but you do not specify a preferred installation location. Depending on several factors, the system will decide where to install your application. Users can also move your application between internal and external storage.
When your application is installed on external storage:
* as long as external storage is mounted on the device, installing the application on external storage has no effect on the performance of the application.
* . apk files are saved on external storage, but all users ' private data, databases, optimized. dex files, and additional local code are stored on the internal device memory.
* The specific memory installed for your application will be encrypted with a randomly generated key that can be decrypted by the device that originally installed the application. As a result, an application installed on an SD card can only run on a single device.
* Users can use the system settings to move your application to internal storage.
Note: When the user enables USD device storage mode to share files with the computer, or if the SD card is uninstalled through the system settings, the external storage will be uninstalled from the device and all applications running on the external storage will end up being killed immediately.
1. Backwards compatibility
Only devices running API Level 8 (Android 2.2) or later allow your application to be installed on external storage. Existing applications that have been compiled with less than API Level 8 can only be installed on internal storage and cannot be moved to external storage (even if the device on which the program is installed is running Android 2.2 or later). However, if your application must support versions that are below API Level 8, you can still provide this functionality for devices running API Level 8 or later and are compatible with devices that are less than the API Level 8 version.
To allow applications to be installed on external storage and still compatible with versions below API Level 8, you need to:
1.1 Add the Android:installlocation attribute to the <manifest> tag in the manifest file and set the value to "Auto" or "preferexternal".
1.2 continue to keep your android:minsdkversion property (below the value of version 8) and make sure that your application's code uses only the API that is compatible with this version.
1.3 to be able to compile your application, change your android:targetsdkversion to 8 or higher. This is necessary because the old Android library does not recognize the Android:installlocation attribute, which will result in your application being unable to compile.
When your application is installed on a device that is below API Level 8, the Android:installlocation attribute is ignored and the application is installed on the internal storage.
Warning: Although XML tags like this are ignored on older versions of the platform, when your minsdkversion is less than "8", you should be careful not to use API level 8 in your code to provide the API, Unless you do the necessary work to ensure that your code is backwards compatible (version-determined and then high-version API, etc.).
2. Applications that should not be installed on external storage
Applications installed on external storage are immediately killed when the user enables USB storage mode to share files with their computer (or to uninstall and remove external memory directly). These applications will not be recognized until the USB storage mode is turned off and the external storage is re-mounted on the device. In addition to killing applications and making them unusable, this can also cause some types of applications to have more serious consequences. To keep your application running as expected, if your application uses the features listed below, you should not install the application on external storage to prevent external storage from being uninstalled:
2.1 Services: The service you run will be killed and will not run again after the external storage is mounted again. Of course, you can also register action_external_applications_available-type intent broadcasts, which will notify your application when the system can re-use applications installed on external storage. After you receive the broadcast, you can restart your service.
2.2 Alarm Services (alarm clock/System timer service): your alarm clock registered with Alarmmanager will be canceled. You must manually re-register these alarms after the external storage is mounted again.
2.3 Input Method Engines (IME, input): your input method will be replaced by the default input method. When the external storage is re-mounted, the user can turn on system settings to re-enable your IME.
2.4 Live Wallpapers (Live wallpaper): The Live wallpaper You run will be replaced by the default live wallpaper. When the external storage is re-mounted, the user can re-select your Live wallpaper.
2.5 App Widget (widgets): your widgets will be removed from the home screen. When the external storage is re-mounted, your widgets are not available to the user until the system resets the application on top of the home (usually waiting for the system to restart).
2.6 Account Manager: Accounts created with Accountmanager disappear, knowing that external storage is re-mounted.
2.7 Sync Adapter (sync adapter): your abstractthreadedsyncadapter and its sync function will stop working until the external storage is re-mounted.
2.8 Device Administrators: your evil deviceadminreceive and all of its administrative privileges will be disabled, which may cause unforeseen consequences for the device's functionality, And may continue after the external storage is re-mounted.
2.9 Listen for "Device boot complete" broadcast receivers: The system publishes action_boot_completed broadcasts before the external storage is mounted on the device. If your application is installed on an external storage, it will not be able to receive this broadcast.
If your application uses some of the features listed above, you should not allow your application to be installed on external storage. By default, your application is not allowed to be installed on external storage, so you don't have to worry about the applications you've already published. However, if you need to make sure that your application is never installed on the external storage, you can clearly declare the Android:installlocation property and assign the value "Internalonly". Although this does not change the default settings, it can be clear that your application can only be installed on internal storage and remind yourself or other developers of this decision.
3. Applications that should be installed on external storage
Simply put, any application that does not use the previously listed features is safe to install on external storage. Large games are usually allowed to be installed on external storage because the game usually does not provide services that run when it is on standby. When external storage is unavailable, the game process is killed. When the external storage is re-usable and the user restarts the game, there should be no effect on the visual interface (assuming the game correctly preserves its state through the standard activity lifecycle).
If your application requires several megabytes of apk files, you need to carefully consider whether to allow the application to be installed on external storage to save the user internal storage space.
Original address: http://developer.android.com/guide/topics/data/install-location.html
Android App installation location (app install site)