本文主要是记录下代码功能,刚好用到设置桌面功能,在华为手机上设置奔溃,然后看到是跳转桌面原因,就找了下。哈哈哈,还是挺容易找的,刚开始测试以为不行,调用直接返回桌面了,这里给新手提个醒:需要下载有设置桌面的App软件,才会弹出桌面设置默认选项。到此记录完毕。如果有疑问可以联系本人QQ 731712249,以下代码都是拷贝而来哈
private void setDefaultL() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(“android.intent.category.HOME”);
try {
intent.setComponent(new ComponentName(“android”, “com.android.internal.app.ResolverActivity”));
startActivity(intent);
} catch (Exception e) {//这里就是为了处置华为手机的
try {
intent.setComponent(new ComponentName(“com.huawei.android.internal.app”, “com.huawei.android.internal.app.HwResolverActivity”));//这个类有些华为手机找不到
startActivity(intent);
} catch (Exception e1) {
e1.printStackTrace();
try {
startHuaweiSettingActOfDefLauncher();//开启桌面设置
} catch (Exception e2) {
e2.printStackTrace();
intent = new Intent(Settings.ACTION_APPLICATION_SETTINGS);//还不行,就只能应用程序设置了
startActivity(intent);
}
}
}
}
public void startHuaweiSettingActOfDefLauncher() {
IntentFilter localIntentFilter = new IntentFilter();
localIntentFilter.addAction(Intent.ACTION_MAIN);//”android.intent.action.MAIN”
localIntentFilter.addCategory(Intent.CATEGORY_HOME);//”android.intent.category.HOME”
Intent localIntent3 = new Intent(localIntentFilter.getAction(0));
localIntent3.addCategory(localIntentFilter.getCategory(0));
Intent localIntent4 = new Intent();
localIntent4.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
localIntent4.setClassName(“com.android.settings”, “com.android.settings.Settings$PreferredSettingsActivity”);
localIntent4.putExtra(“preferred_app_package_name”, getActivity().getPackageName());
localIntent4.putExtra(“preferred_app_class_name”, getActivity().getClass().getName());
localIntent4.putExtra(“is_user_confirmed”, true);
localIntent4.putExtra(“preferred_app_intent”, localIntent3);
localIntent4.putExtra(“preferred_app_intent_filter”, localIntentFilter);
localIntent4.putExtra(“preferred_app_label”, “默认桌面设置”);
startActivity(localIntent4);
}