按钮点击

时间:2016-12-28 06:53:53

标签: android

嗨,大家好我正在制作网页浏览器,我面临一些问题,我正在使我的浏览器默认,但当我想清除默认浏览器,如果任何其他浏览器是默认的,那么它将显示安全异常我使用此getActivity().getPackageManager().clearPackagePreferredActivities(currentHomePackage); 借助于此我可以清除自己的包但不是其他默认的浏览器包 我希望清除默认浏览器只需点击按钮我不想打开设置程序任何人帮助我伙计

packageManager = getActivity().getPackageManager();
        resolveInfo = packageManager.resolveActivity(i, PackageManager.MATCH_DEFAULT_ONLY);
        currentHomePackage = resolveInfo.activityInfo.packageName;
         Uri uri = Uri.parse(Constants.DefaultURL);
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.addCategory(Intent.CATEGORY_DEFAULT);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.setData(uri);

   if (switchButton.isChecked()) {

                if (resolveInfo.activityInfo.packageName.equalsIgnoreCase(getActivity().getPackageName()) || resolveInfo.activityInfo.packageName.equalsIgnoreCase("android")) {
                   /* SharedPreferences.Editor editor = sharedPref.edit();
                    editor.putBoolean(Constants.DefaultBrowserSetting, true);
                    editor.commit();*/
                    Log.d("ppp checked", "--" + currentHomePackage);
                    startActivity(i);
                } else {

getActivity().getPackageManager().clearPackagePreferredActivities(currentHomePackage);
                }
            } else {
                packageManager.clearPackagePreferredActivities(getActivity().getPackageName());
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putBoolean(Constants.DefaultBrowserSetting, false);
                editor.commit();
                switchButton.setChecked(false);
            }
        }

1 个答案:

答案 0 :(得分:0)

SecurityException表示您在清单文件中缺少某些权限。给予所需的许可。你可以在谷歌搜索更多 android中的权限。