zoukankan      html  css  js  c++  java
  • android-android各大手机系统打开权限管理页面

    android系统五花八门,当我们去请求用户的权限的时候,总是会弹出是否允许的对话框。

    而且用户一旦不小心点了拒绝,下次就不再询问了,而很多小白用户也不知道怎么去设置。这就导致了很不好的用户体验。

    经过研究,我发现像小米,魅族,这些满大街的系统,都是可以通过隐式意图打开权限设置页面的。

    这里指的是自身app的权限管理页面

    之前已经有人写过类似的文章,不过都比较分散,我这里把这些方法总结了一下。

    不多说,直接上代码。

    首先是最蛋疼的小米,百度了很多前辈留下的方法,发现都不能打开,没有办法,只能通过 adb dumpsys activity activities 命令去查看

    经过一番研究终于打开了。

        /**
         * 跳转到miui的权限管理页面
         */
        private void gotoMiuiPermission() {
            Intent i = new Intent("miui.intent.action.APP_PERM_EDITOR");
            ComponentName componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
            i.setComponent(componentName);
            i.putExtra("extra_pkgname", getPackageName());
            try {
                startActivity(i);
            } catch (Exception e) {
                e.printStackTrace();
                gotoMeizuPermission();
            }
        }

    接下来上魅族的代码

        /**
         * 跳转到魅族的权限管理系统
         */
        private void gotoMeizuPermission() {
            Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.putExtra("packageName", BuildConfig.APPLICATION_ID);
            try {
                startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
                gotoHuaweiPermission();
            }
        }

    华为的系统由于不太一样,有些系统是华为自己的权限管理,而6.0的是用的原生的权限管理页面,目前手上只有一台6.0的华为手机,

    暂时没有研究到打开的方法,如果有知道的大神麻烦告知一下

    不过打不开没关系,我们可以退而求其次,打开所用应用的权限管理页面

        /**
         * 华为的权限管理页面
         */
        private void gotoHuaweiPermission() {
            try {
                Intent intent = new Intent();
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                ComponentName comp = new ComponentName("com.huawei.systemmanager", "com.huawei.permissionmanager.ui.MainActivity");//华为权限管理
                intent.setComponent(comp);
                startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
                startActivity(getAppDetailSettingIntent());
            }
    
        }

    目前也就研究了这三大系统,对于原生系统,和其他系统,如果找不到方法,也可以先把用户引导到系统设置页面

        /**
         * 获取应用详情页面intent
         *
         * @return
         */
        private Intent getAppDetailSettingIntent() {
            Intent localIntent = new Intent();
            localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            if (Build.VERSION.SDK_INT >= 9) {
                localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                localIntent.setData(Uri.fromParts("package", getPackageName(), null));
            } else if (Build.VERSION.SDK_INT <= 8) {
                localIntent.setAction(Intent.ACTION_VIEW);
                localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
                localIntent.putExtra("com.android.settings.ApplicationPkgName", getPackageName());
            }
            return localIntent;
        }

    获取到intent之后直接startactivity就好了。。。

  • 相关阅读:
    Leetcode Excel Sheet Column Number
    AlgorithmsI PA2: Randomized Queues and Deques Subset
    AlgorithmsI PA2: Randomized Queues and Deques RandomizedQueue
    AlgorithmsI PA2: Randomized Queues and Deques Deque
    AlgorithmsI Programming Assignment 1: PercolationStats.java
    hdu多校第四场 1003 (hdu6616) Divide the Stones 机智题
    hdu多校第四场 1007 (hdu6620) Just an Old Puzzle 逆序对
    hdu多校第四场1001 (hdu6614) AND Minimum Spanning Tree 签到
    hdu多校第三场 1007 (hdu6609) Find the answer 线段树
    hdu多校第三场 1006 (hdu6608) Fansblog Miller-Rabin素性检测
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6072629.html
Copyright © 2011-2022 走看看