PackageManagerService安装包的机制如下:
在 AdroidManifest.xml 里面定义安装位置可以有四种情况:在 packages\apps\Settings\src\com\android\settings中ApplicationSettings.java
// Is app default install location set?
boolean userSetInstLocation = (Settings.System.getInt(getContentResolver(),
Settings.Secure.SET_INSTALL_LOCATION, 0) != 0);
if (!userSetInstLocation) {
getPreferenceScreen().removePreference(mInstallLocation);
} else {
mInstallLocation.setValue(getAppInstallLocation());
mInstallLocation.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = (String) newValue;
handleUpdateAppInstallLocation(value);
return false;
}
});
}
修改Settings.Secure.SET_INSTALL_LOCATION此值即可显示用户选择菜单
可以按照如下方式更改,这样用户就能自己选择安装位置:
打开 frameworks/base/packages/SettingsProvider/DatabaseHelper.java将loadSetting(stmt, Secure.SET_INSTALL_LOCATION, 0);改为 loadSetting(stmt, Secure.SET_INSTALL_LOCATION, 1);
将loadSetting(stmt, Settings.Secure.SET_INSTALL_LOCATION, 0);改为 loadSetting(stmt, Settings.Secure.SET_INSTALL_LOCATION, 1);
如何设置安装位置默认为SD卡
将 loadSetting(stmt, Secure.DEFAULT_INSTALL_LOCATION,PackageHelper.APP_INSTALL_AUTO);修改为
loadSetting(stmt, Secure.DEFAULT_INSTALL_LOCATION,PackageHelper.APP_INSTALL_EXTERNAL);
将 loadSetting(stmt, Settings.Secure.DEFAULT_INSTALL_LOCATION,PackageHelper.APP_INSTALL_AUTO);修改为
loadSetting(stmt, Settings.Secure.DEFAULT_INSTALL_LOCATION,PackageHelper.APP_INSTALL_EXTERNAL);