失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Android 设置华为手机跳转默认桌面

Android 设置华为手机跳转默认桌面

时间:2022-07-12 14:07:25

相关推荐

Android 设置华为手机跳转默认桌面

本文主要是记录下代码功能,刚好用到设置桌面功能,在华为手机上设置奔溃,然后看到是跳转桌面原因,就找了下。哈哈哈,还是挺容易找的,刚开始测试以为不行,调用直接返回桌面了,这里给新手提个醒:需要下载有设置桌面的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);

}

如果觉得《Android 设置华为手机跳转默认桌面》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。