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);
    }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值