對於Android 2.2開始的軟體可以裝到到SD上的支援,對於adb命令而言也有了改進,對於Android 2.2固件中的pm命令開支援安裝選項參數,這裡新增了參數setInstallLocation,這裡我們可以用adb通過shell命令執行linux的pm添加一些參數即可,比如adb shell pm setInstallLocation 0。其中最後一個參數0代表auto自動的,Android系統會自動選擇,而1為手機內部的rom,2為外部sd卡存儲,主要解釋如下


adb shell pm setInstallLocation
option

option 的值可以為以下數位

0 [auto] Let the system decide. 自動

1 [internal only] ROM中

2 [external] SD卡中

這裡android123推薦大家對於經常用的小軟體可以安裝在手機內部,比如來電管理、系統工具這樣可以提供更高的可靠性節省電量,而遊戲類應用可以考慮安裝到SD卡上,對於檔大小超過4MB的APK可以考慮安裝到SD卡上,通過電腦牆紙讓apk安裝到sd卡的命令為

adb shell pm setInstallLocation 2

當然Android開發網提醒大家,還有新的獲取安裝的位置參數為getInstallLocation,我們使用adb shell pm getInstallLocation來獲取軟體的安裝位置清單。





在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。
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()