决定app安装位置的因素有两个: 1、app内部的AndroidManifest.xml文件中定义android:installLocation的属性 2、设置->存储中首选安装位置 android:installLocation属性设置分为4中情况: 1、android:installLocation="auto" //如果定义为auto,那么该app会被安装到手机内存,也就是data分区(/data/app目录)下,可以被移动; 2、android:installLocation="internalOnly" //如果定义为internalOnly,那么该app就只能被安装到data分区(/data/app目录)下,不可被移动; 3、android:installLocation="preferExternal" //如果定义为preferExternal,那么该app会被安装到SD卡中,SD卡满了,app就会被安装到手机内存;该app是可以在手机内存和SD卡之间进行Move操作的; 4、未定义该属性 //如果没有定义该属性,那么默认会安装到手机内存,不可移动。 app在安装时,首先会看android:installLocation属性,如果属性定义了,那么就会根据定义的属性来决定安装位置;如果没有定义该属性,那么就会根据系统设置来决定。系统默认是安装到手机内存,如果在设置中首选安装位置选择了手机存储,那么该app就会被安装到手机存储。
在系统设置中,一般是没有开启 应用程序首选安装位置选项的,如果要开启该选项,可以做如下修改:
修改frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java文件,
找到loadSetting(stmt, Settings.Global.SET_INSTALL_LOCATION, 0);
SET_INSTALL_LOCATION这个值默认是0,设为1后,设置项中就有会该菜单项。