Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 高級開發 >> Android2.2中的APK安裝參數installLocation

Android2.2中的APK安裝參數installLocation

編輯:高級開發

android 2.2中新的特性可以支持類似APP2SD卡上,我們的APK文件可以安裝在SD卡上供用戶使用,android123今天就說下目前項目的升級和一些配置。

1. 首先讓你的程序支持SD卡上安裝必須具備設置API Level至少為8,即androidmanifest.xml的中android:minSdkVersion至少為8這樣你的APK最終運行時兼容的固件只有2.2了,同時在androidmanifest.XML文件的根節點中必須加入android:installLocation這個屬性,類似代碼如下:

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

2. android:installLocation的值主要有preferExternal、auto和internalOnly這三個選項,通常我們設置為preferExternal可以優先推薦應用安裝到SD卡上,當然最終用戶可以選擇為內部的ROM存儲上,如果外部存儲已滿,android內部也會安裝到內部存儲上,auto將會根據存儲空間自適應,當然還有一些應用可能會有特殊的目的,他們一般必須安裝在內部存儲才能可靠運行,設置為internalOnly比較合適,主要體現在:

Services 服務
Your running Service will be killed and will not be restarted when external storage is remounted. You can, however, register for the ACTION_EXTERNAL_APPLICATIONS_AVAILABLE broadcast Intent, which will notify your application when applications installed on external storage have become available to the system again. At which time, you can restart your Service. android123提示大家一般實時後台監控類的應用都應該裝到內部存儲,比較可靠。

Alarm Services 鬧鈴提醒服務
Your alarms registered with AlarmManager will be cancelled. You must manually re-register any alarms when external storage is remounted.

Input Method Engines 輸入法引擎
Your IME will be replaced by the default IME. When external storage is remounted, the user can open system settings to enable your IME again.

Live Wallpapers 活動壁紙
Your running Live Wallpaper will be replaced by the default Live Wallpaper. When external storage is remounted, the user can select your Live Wallpaper again.

Live Folders 活動文件夾
Your Live Folder will be removed from the home screen. When external storage is remounted, the user can add your Live Folder to the home screen again.

App Widgets Widget
Your App Widget will be removed from the home screen. When external storage is remounted, your App Widget will not be available for the user to select until the system resets the home application (usually not until a system reboot).

Account Managers 賬戶管理
Your accounts created with AccountManager will disappear until external storage is remounted.

Sync Adapters 同步適配器
Your AbstractThreadedSyncAdapter and all its sync functionality will not work until external storage is remounted.

Device Administrators 設備管理器
Your DeviceAdminReceiver and all its admin capabilitIEs will be disabled, which can have unforeseeable consequences for the device functionality, which may persist after external storage is remounted.

那麼哪些應用適合安裝在SD卡中呢? android開發網建議一些占用資源比較大的游戲,比如大於3MB的單個文件,不需要長期駐留內存的應用,不具備提醒和實時監控的應用一般放到SD卡上比較合適,不過目前想讓你的應用裝到SD卡上,必須設置API Level至少為8以上,同時顯示注明android:installLocation。

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved