感谢分享

概述

最近项目中遇到这样个需求场景:
当我们的用户使用App时不小心拒绝了某项必要权限,而导致无法正常使用。这时候希望重新去打开该权限,那么问题来了,Android厂家定制的room五花八门,很多时候却发现找不到权限管理的入口。为了解决这一问题,如果我们应用中直接提供权限管理入口给用户,是不是会很方便的解决用户这一困扰呢?经过一番研究,整理出了大部分国产手机直接打开权限管理界面的方法:

华为

Intent intent = new Intent();intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.putExtra("packageName", BuildConfig.APPLICATION_ID);ComponentName comp = new ComponentName("com.huawei.systemmanager", "com.huawei.permissionmanager.ui.MainActivity");intent.setComponent(comp);startActivity(intent);

魅族

Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");intent.addCategory(Intent.CATEGORY_DEFAULT);intent.putExtra("packageName", BuildConfig.APPLICATION_ID);startActivity(intent);

小米

Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");ComponentName componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");intent.setComponent(componentName);intent.putExtra("extra_pkgname", BuildConfig.APPLICATION_ID);startActivity(intent);

索尼

Intent intent = new Intent();intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.putExtra("packageName", BuildConfig.APPLICATION_ID);                    ComponentName comp = new ComponentName("com.sonymobile.cta", "com.sonymobile.cta.SomcCTAMainActivity");intent.setComponent(comp);startActivity(intent);

OPPO

Intent intent = new Intent();intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.putExtra("packageName", BuildConfig.APPLICATION_ID);                    ComponentName comp = new ComponentName("com.color.safecenter", "com.color.safecenter.permission.PermissionManagerActivity");intent.setComponent(comp);startActivity(intent);

LG

Intent intent = new Intent("android.intent.action.MAIN");intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.putExtra("packageName", BuildConfig.APPLICATION_ID);ComponentName comp = new ComponentName("com.android.settings", "com.android.settings.Settings$AccessLockSummaryActivity");intent.setComponent(comp);startActivity(intent);

乐视

Intent intent = new Intent();intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.putExtra("packageName", BuildConfig.APPLICATION_ID);ComponentName comp = new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.PermissionAndApps");intent.setComponent(comp);

360手机(只能打开到自带安全软件)

Intent intent = new Intent("android.intent.action.MAIN");intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.putExtra("packageName", BuildConfig.APPLICATION_ID);ComponentName comp = new ComponentName("com.qihoo360.mobilesafe", "com.qihoo360.mobilesafe.ui.index.AppEnterActivity");intent.setComponent(comp);startActivity(intent);

由于资源和能力有限,只研究这些,其他厂家的适配,可以引导用户到系统设置页面,或者应用信息(有些厂家会直接在应用信息提供权限管理入口);提一下,对于三星手机,尝试过很多方法,但都没能成功,自己项目中是直接引导用户到应用信息页面。下面是两个通用的方法,一个是引导至系统设置页面,另一个引导至应用信息页面:

应用信息界面

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()); } startActivity(localIntent);

系统设置界面

Intent intent =  new Intent(Settings.ACTION_SETTINGS);startActivity(intent);

补充

1、手机的Build.MANUFACTURER,仅供参照,不排除个别厂家有作更改,有没列到或者修正的欢迎小伙伴们留言,后续更新,谢谢

华为——Huawei魅族——Meizu小米——Xiaomi索尼——Sonyoppo——OPPOLG——LGvivo——vivo三星——samsung乐视——Letv中兴——ZTE酷派——YuLong联想——LENOVO

2、6.0权限检查示例代码

if (Build.VERSION.SDK_INT >= 23) {            if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {                // 没有权限                if(ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CALL_PHONE)){                    //如果没勾选“不再询问”,向用户发起权限请求                    ActivityCompat.requestPermissions((Activity) mContext, new String[]{Manifest.permission.CALL_PHONE}, 0);                }else{                    //之前点击了“不再询问”,无法再次弹出权限申请框。                    //可以给Toast提示,或者Dialog反馈给用户,引导去开启相应权限                    // 去应用信息                    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", mContext.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", mContext.getPackageName());                    }                }            } else {                // 有权限,接着你要干的活            }        } else {            // 6.0之前的系统,因为无法获取权限的状态,直接执行需要权限的操作        }

3、小伙伴补充的,小米系统适配代码 感谢@name__repeated童鞋

String rom = getMiuiVersion();        Intent intent = null;        if (ROM_MIUI_V5.equals(rom)) {            Uri packageURI = Uri.parse("package:" + context.getApplicationInfo().packageName);            intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);        } else if (ROM_MIUI_V6.equals(rom) || ROM_MIUI_V7.equals(rom)) {            intent = new Intent("miui.intent.action.APP_PERM_EDITOR");            intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");            intent.putExtra("extra_pkgname", context.getPackageName());        } else {        }

更多相关文章

  1. Android(安卓)Studio安卓学习笔记(三)Android用户界面的设计布局
  2. Android(安卓)MVC 架构详解
  3. 浅析Android(安卓)4.0的通知系统(附Android(安卓)4.0设计指南全文
  4. Android应用程序用户界面(十二)菜单
  5. android UI设计之思考
  6. Android最佳实践 为响应灵敏性设计
  7. Android(安卓)app实现自更新和安装,权限检测适配Android6.0以下和
  8. Android(安卓)4.0 消息广播无法接收的原因
  9. Android(安卓)UI 设计谨记

随机推荐

  1. Android(安卓)的网络编程(7)-检测网络是
  2. Android下拉刷新上拉加载控件,对所有View
  3. Android 直连SQL
  4. Android:反编译查看源码
  5. C++开发安卓、windows下搭建Android NDK
  6. Android文章说明总结
  7. 《Android(安卓)JNI》01 配置环境
  8. Android中AppWidget加载流程
  9. [置顶] GPSMapEdit
  10. android opencv环境的搭建