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: <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 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.
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
file is saved on the external storage, but all private user data, databases, optimized.apk
files, and extracted native code are saved on the internal device memory..dex
- 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.
揀重點說一下這篇文章。這篇技術文檔主要核心内容是講,從Android API Level 8開始,Android APP開發者可以在自己的APP中程式設計設定APP安裝的位置:安裝在外置/外部擴充存儲卡上(比如裝置上使用者插入的擴充SD卡)。這一特色的實作,隻需在Android的manifest設定:
android:installLocation
的屬性值。如果開發者沒有設定這一值,那麼,Android系統将會把你的APP安裝在内置/内部存儲中并且不允許被移動到外部/外置存儲。
是以,為了能讓系統把你的APP安裝在外部/外置擴充存儲中,你需要在manifest修改
android:installLocation
的屬性值,把
android:installLocation
設定為"
preferExternal
" o或者"
auto
"。
如果你聲明了"
preferExternal
"(
android:installLocation
= "
preferExternal
",),意即為要求系統将你的APP安裝在外部/外置擴充存儲,但是系統并一定總是這麼做。假設外部/外置存儲已滿,系統仍然會将你的APP安裝在内部/内置存儲。當使用者安裝了你的APP後,使用者可以把你的APP在外部/外置和内部/内置存儲之間來回移動。
如果你聲明了 "
auto
android:installLocation
="auto"),你意圖讓系統把你的APP安裝在外部/外置存儲,但是你沒有對安裝位置有特别偏好。是以最終還是由系統綜合考量若幹因素然後決定你的APP安裝的位置,同時,使用者仍然可以自主的在外部和内部存儲之間來回移動你的APP。
更多其他詳細細節内容,請看原始谷歌官方文檔,文檔連結位址:
http://developer.android.com/guide/topics/data/install-location.html#Compatiblity