参考了一下两篇文章:
http://blog.csdn.net/jia4525036/article/details/18036765
http://blog.sina.com.cn/s/blog_4ad8d46c01019zq4.html
由于项目需求更改,在此做保留以后方便使用
在 frameworks/base/core/java/com/android/internal/app/ResolverActivity.java 中作修改
根据需要默认Launcher来设置默认
private void setDefaultLauncher(String defPackageName,String defClassName) {
if ((defPackageName != null && defPackageName.trim().length() > 1) && (defClassName != null && defClassName.trim().length() > 0)) {
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.MAIN");
filter.addCategory("android.intent.category.HOME");
filter.addCategory("android.intent.category.DEFAULT");
Intent intent=new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
List
list = getPackageManager().queryIntentActivities(intent, 0);
final int N = list.size();
ComponentName[] set = new ComponentName[N];
int bestMatch = 0;
for (int i=0; i
set[i] = new ComponentName(r.activityInfo.packageName,
r.activityInfo.name);
if (r.match > bestMatch) bestMatch = r.match;
}
ComponentName preActivity = new ComponentName(defPackageName, defClassName);
getPackageManager().addPreferredActivity(filter, bestMatch, set,preActivity);
}
}
在onCreate方法中添加调用
protected void onCreate(Bundle savedInstanceState) {
//++++++++++++
boolean firstBoot = (Settings.System.getInt(getApplication().getContentResolver(),
Settings.System.DEFAULT_HOME_SETTING_CHANGED, 0) == 0);
if(firstBoot){
String defPackageName = "com.panasonic.india.flexuihome";
String defClassName = "com.panasonic.india.flexuihome.Launcher";
setDefaultLauncher(defPackageName,defClassName);
android.util.Log.i("deflauncher : ","deflauncher : PackageName = "+
defPackageName+" ClassName = "+defClassName);
Intent defIntent = new Intent();
defIntent.setClassName(defPackageName, defClassName);
defIntent.setAction("android.intent.action.MAIN");
defIntent.addCategory("android.intent.category.HOME");
defIntent.addCategory("android.intent.category.DEFAULT");
startActivity(defIntent);
Settings.System.putInt(getApplication().getContentResolver(),
Settings.System.DEFAULT_HOME_SETTING_CHANGED,1);
this.finish();
}
//++++++++++++
// Use a specialized prompt when we're handling the 'Home' app startActivity()
final int titleResource;
final Intent intent = makeMyIntent();
final Set
if (Intent.ACTION_MAIN.equals(intent.getAction())
&& categories != null
&& categories.size() == 1
&& categories.contains(Intent.CATEGORY_HOME)) {
titleResource = com.android.internal.R.string.whichHomeApplication;
} else {
titleResource = com.android.internal.R.string.whichApplication;
}
onCreate(savedInstanceState, intent, getResources().getText(titleResource),
null, null, true);
}
DEFAULT_HOME_SETTING_CHANGED的设置
在core/java/android/provider/Settings.java的public static final class System extends NameValueTable{}中添加
public static final String DEFAULT_HOME_SETTING_CHANGED = "default_home_setting_changed";
packages/SettingsProvider/res/values/defaults.xml中添加
packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
在private void loadSystemSettings(SQLiteDatabase db){}中添加中添加
loadIntegerSetting(stmt, Settings.System.DEFAULT_HOME_SETTING_CHANGED, R.integer.default_launcher_value);
---------------------
作者:烟雨唯梦
来源:CSDN
原文:https://blog.csdn.net/u011609787/article/details/46519975
版权声明:本文为博主原创文章,转载请附上博文链接!