"Mobile development" APP Install location

Source: Internet
Author: User
Tags home screen

Beginning with API Level 8, you can allow your application to be installed on the external storage (for example, the Devic E ' s SD card). This is a optional feature you can declare for your application with the android:installLocation manifest attribute. If you don't declare this attribute, your application'll be installed on the internal storage only and it Cann OT 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 at android:installLocation Tribute in the <manifest> element, with a value of either "" preferExternal or " auto ". For example:

<manifestxmlns:android="Http://schemas.android.com/apk/res/android"
Android:installlocation="Preferexternal"
>

If you declare ' preferExternal ", you request the your application is installed on the external storage, and the system does not g Uarantee that your application would be a installed on the external storage. If the external storage is full, the system would install it on the internal storage. The user can also move your application between the locations.

If you declare " auto ", you indicate this your application may be installed on the external storage, but you don ' t has a Preference of install location. The system would decide where to install your application based on several factors. The user can also move your application between the locations.

When your application are installed on the external storage:

    • There is no effect on the application performance so long as the external storage are mounted on the device.
    • .apkthe file is saved on the external storage, but all private user data, databases, optimized .dex files, and Extracte D native code is saved on the internal device memory.
    • The unique container in which your application is stored are encrypted with a randomly generated key so can be decrypted Only by the device, that originally installed it. Thus, an application installed on a 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 .

Backward compatibility

The ability for your application to install on the external storage are a feature available only on devices running API Lev El 8 (Android 2.2) or greater. Existing applications that were built prior to API level 8 would always install on the internal storage and cannot be moved To the external storage (even in devices with API level 8). However, if your application is designed to support a API level lower than 8, you can choose to support this FEA Ture for Devices with API level 8 or greater and still is compatible with devices using a API level lower than 8.

To allow installation in external storage and remain compatible with versions lower than API Level 8:

    1. Include the android:installLocation attribute with a value of " auto " or "in the preferExternal <manifest> element.
    2. Leave your android:minSdkVersion attribute as is (something less than "8") and being certain that your application code uses only AP is compatible with the level.
    3. In order to compile your application, the change your build target to API level 8. This is necessary because older Android libraries don ' t understand the attribute and would not compile your applicati android:installLocation On when it ' s present.

When your application was installed on a device with an API level lower than 8, the android:installLocation attribute is ignored and the APPL Ication is installed on the internal storage.

Caution: Although XML markup such as this would be ignored by older platforms, you must is careful not to use programming APIs intro duced in API Level 8 while your minSdkVersion are less than "8", unless you perform the work necessary to provide backward Compatib Ility in your code.

Applications that should not Install on External Storage

When the user enables USB mass storage to share files with their computer (or otherwise unmounts or removes the external s Torage), any application installed on the external storage and currently running are killed. The system effectively becomes unaware of the application until mass storage are disabled and the external storage is Remou Nted 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. In order for your application to consistently behave as expected, you should not allow your application to be INS Talled on the external storage if it uses all of the following features, due to the cited consequences when the external s Torage is unmounted:

Services
Your running'll be killed and'll not being
Service restarted when external storage is remounted. Can, however, register for the ACTION_EXTERNAL_APPLICATIONS_AVAILABLE broadcast Intent, which would notify your application when applications Installe D on external storage has become available to the system again. At which time, you can restart your Service.
Alarm Services
Your alarms registered with'll be AlarmManager cancelled. You must manually re-register any alarms then external storage is remounted.
Input Method Engines
Your IME is replaced by the default IME. When external storage was remounted, the user can open system settings to enable your IME again.
Live Wallpapers
Your running Live wallpaper would be replaced by the default live wallpaper. When external storage is remounted, the user can select your Live wallpaper again.
APP Widgets
Your App Widget is removed from the home screen. When external storage is remounted, your App Widget won't be available for the user to select until the Syst EM resets the home application (usually not until a system reboot).
Account Managers
Your accounts created with would AccountManager disappear until
external storage is remounted.
Sync Adapters
Your and all its
AbstractThreadedSyncAdapter sync functionality won't work until external storage are remounted.
Device Administrators
Your DeviceAdminReceiver and all its admin capabilities'll be disabled, which can has unforeseeable consequences for the Devi CE functionality, which may persist after external storage is remounted.
Broadcast receivers listening for "boot completed"
The
system delivers the ACTION_BOOT_COMPLETED broadcast before the external storage is mounted to the device. If your application is installed on the external storage, it can never receive this broadcast.

If your application uses any of the features listed above, you should not allow your application to install on EX ternal storage. By default, the system won't allow your application to install on the external storage, so you don ' t need to W Orry about your existing applications. However, if you ' re certain that your application should never is installed on the external storage and then your should make T His clear by declaring with android:installLocation a value of " internalOnly ". Though This does no change the default behavior, it explicitly states that your application should only being installed on T He internal storage and serves as a reminder to you and the other developers so this decision have been made.

Applications that should Install on External Storage

In simple terms, anything this does not use the features listed in the previous section is safe when installed on Externa L Storage. Large Games is more commonly the types of applications. Should allow installation on external storage, because games Don ' t typically provide additional services when inactive. When external storage becomes unavailable and a game process are killed, there should be no visible effect when the storage becomes available again and the user restarts the game (assuming that the game properly saved it state during the normal Activity lifecycle).

If your application requires several megabytes for the APK file, you should carefully consider whether to enable the Appli Cation to install in the external storage so, users can preserve space on their internal storage.

"Mobile development" APP Install location

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.