Android apk 安裝到sd卡

來源:互聯網
上載者:User

對於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 IME引擎
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。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.