从Level8(版本2.2)开始,可以将App安装到外部存储器(如SD卡)。通过在manifest属性中声明android:installLocation实现该功能,如果不声明,应用只会安装到内部存储器,并且不能转移到外部存储中。

在AndroidManifest.xml中加上属性android:installLocation,设置为preferExternal或auto

<manifestxmlns:android="http://schemas.android.com/apk/res/android"

android:installLocation="preferExternal"

...>

【安装到外部存储中】

  • 不会影响App性能;
  • .apk文件保存在外部存储中,而用户私有数据、数据库等保存在内部存储中;
  • 由于存储App的容器由手机唯一加密,所以SD卡上的所有应用只能在本手机上解密使用。

【注意】

当手机开启USB大容量存储(USBmassstorage)与电脑连接共享文件,或通过系统设置卸载SD卡后,所有外部存储中的应用都无法运行使用。

当App存在以下特性时,不要安装到外部存储中

Services

YourrunningServicewillbekilledandwillnotberestartedwhenexternalstorageisremounted.Youcan,however,registerfortheACTION_EXTERNAL_APPLICATIONS_AVAILABLEbroadcastIntent,whichwillnotifyyourapplicationwhenapplicationsinstalledonexternalstoragehavebecomeavailabletothesystemagain.Atwhichtime,youcanrestartyourService.

AlarmServices

YouralarmsregisteredwithAlarmManagerwillbecancelled.Youmustmanuallyre-registeranyalarmswhenexternalstorageisremounted.

InputMethodEngines

YourIMEwillbereplacedbythedefaultIME.Whenexternalstorageisremounted,theusercanopensystemsettingstoenableyourIMEagain.

LiveWallpapers

YourrunningLiveWallpaperwillbereplacedbythedefaultLiveWallpaper.Whenexternalstorageisremounted,theusercanselectyourLiveWallpaperagain.

AppWidgets

YourAppWidgetwillberemovedfromthehomescreen.Whenexternalstorageisremounted,yourAppWidgetwillnotbeavailablefortheusertoselectuntilthesystemresetsthehomeapplication(usuallynotuntilasystemreboot).

AccountManagers

YouraccountscreatedwithAccountManagerwilldisappearuntilexternalstorageisremounted.

SyncAdapters

YourAbstractThreadedSyncAdapterandallitssyncfunctionalitywillnotworkuntilexternalstorageisremounted.

DeviceAdministrators

YourDeviceAdminReceiverandallitsadmincapabilitieswillbedisabled,whichcanhaveunforeseeableconsequencesforthedevicefunctionality,whichmaypersistafterexternalstorageisremounted.

BroadcastReceiverslisteningfor"bootcompleted"

ThesystemdeliverstheACTION_BOOT_COMPLETEDbroadcastbeforetheexternalstorageismountedtothedevice.Ifyourapplicationisinstalledontheexternalstorage,itcanneverreceivethisbroadcast.

根据你的App类型选择安装位置。理论上,所有App可以安全地安装到外部存储中

来源:http://developer.android.com/guide/topics/data/install-location.html#Compatiblity