Android的.apk软件安装到sd卡的方法
對于Android 2.2開始的軟件可以裝到到SD上的支持,對于adb命令而言也有了改進,對于Android 2.2固件中的pm命令開支持安裝選項參數(shù),這里新增了參數(shù)setInstallLocation,這里我們可以用adb通過shell命令執(zhí)行l(wèi)inux的pm添加一些參數(shù)即可,比如adb shell pm setInstallLocation 0。其中最后一個參數(shù)0代表auto自動的,Android系統(tǒng)會自動選擇,而1為手機內(nèi)部的rom,2為外部sd卡存儲,主要解釋如下
?
adb shell pm setInstallLocation
option
option 的值可以為以下數(shù)字
?????? 0 [auto] Let the system decide. 自動
?????? 1 [internal only] ROM中
??????? 2 [external] SD卡中
? 這里android123推薦大家對于經(jīng)常用的小軟件可以安裝在手機內(nèi)部,比如來電管理、系統(tǒng)工具這樣可以提供更高的可靠性節(jié)省電量,而游戲類應(yīng)用可以考慮安裝到SD卡上,對于文件大小超過4MB的APK可以考慮安裝到SD卡上,通過電腦墻紙讓apk安裝到sd卡的命令為
?adb shell pm setInstallLocation 2?
? 當然Android開發(fā)網(wǎng)提醒大家,還有新的獲取安裝的位置參數(shù)為getInstallLocation,我們使用adb shell pm getInstallLocation來獲取軟件的安裝位置列表。
?
?
? 在Android 2.2中新的特性可以支持類似APP2SD卡上,我們的APK文件可以安裝在SD卡上供用戶使用,Android123今天就說下目前項目的升級和一些配置。
?? 1. 首先讓你的程序支持SD卡上安裝必須具備設(shè)置API Level至少為8,即androidmanifest.xml的中android:minSdkVersion至少為8這樣你的APK最終運行時兼容的固件只有2.2了,同時在androidmanifest.xml文件的根節(jié)點中必須加入android:installLocation這個屬性,類似代碼如下:
? <manifest xmlns:android="http://schemas.android.com/apk/res/android"
??? android:installLocation="preferExternal"
??? ... >
? 2. android:installLocation的值主要有preferExternal、auto和internalOnly這三個選項,通常我們設(shè)置為preferExternal可以優(yōu)先推薦應(yīng)用安裝到SD卡上,當然最終用戶可以選擇為內(nèi)部的ROM存儲上,如果外部存儲已滿,Android內(nèi)部也會安裝到內(nèi)部存儲上,auto將會根據(jù)存儲空間自適應(yīng),當然還有一些應(yīng)用可能會有特殊的目的,他們一般必須安裝在內(nèi)部存儲才能可靠運行,設(shè)置為internalOnly比較合適,主要體現(xiàn)在:
Services 服務(wù)
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提示大家一般實時后臺監(jiān)控類的應(yīng)用都應(yīng)該裝到內(nèi)部存儲,比較可靠。
Alarm Services? 鬧鈴提醒服務(wù)
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 設(shè)備管理器
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.
? 那么哪些應(yīng)用適合安裝在SD卡中呢? Android開發(fā)網(wǎng)建議一些占用資源比較大的游戲,比如大于3MB的單個文件,不需要長期駐留內(nèi)存的應(yīng)用,不具備提醒和實時監(jiān)控的應(yīng)用一般放到SD卡上比較合適,不過目前想讓你的應(yīng)用裝到SD卡上,必須設(shè)置API Level至少為8以上,同時顯示注明android:installLocation。
總結(jié)
以上是生活随笔為你收集整理的Android的.apk软件安装到sd卡的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大额存单缺点有哪些?大额存单的弊端
- 下一篇: 一图看懂长期低头对颈椎伤害有多大?低头3