Android如何編程設定APP安裝位置(外部儲存或內部儲存)?

來源:互聯網
上載者:User

標籤:android

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 theandroid: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.

If you declare "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 .apk file is saved on the external storage, but all private user data, databases, optimized.dex files, and extracted native code are saved on the internal device memory.
  • 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。


更多其他詳細細節內容,請看原始Google官方文檔,文檔連結地址:http://developer.android.com/guide/topics/data/install-location.html#Compatiblity

Android如何編程設定APP安裝位置(外部儲存或內部儲存)?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.