最近项目上比较忙,终于有空闲时间写写东西了。
相信做过Android的都知道,现在的手机系统五花八门,当我们去请求用户的权限的时候,总是会弹出是否允许的对话框。
而且用户一旦不小心点了拒绝,下次就不再询问了,而很多小白用户也不知道怎么去设置。这就导致了很不好的用户体验。
经过研究,我发现像小米,魅族,这些满大街的系统,都是可以通过隐式意图打开权限设置页面的。
这里指的是自身app的权限管理页面
之前已经有人写过类似的文章,不过都比较分散,我这里把这些方法总结了一下。
不多说,直接上代码。
首先是最蛋疼的小米,百度了很多前辈留下的方法,发现都不能打开,没有办法,只能通过 adb dumpsys activity activities 命令去查看
经过一番研究终于打开了。
-
-
-
- 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());
- }
-
- }
目前也就研究了这三大系统,对于原生系统,和其他系统,如果找不到方法,也可以先把用户引导到系统设置页面
-
-
-
-
-
- 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就好了。。。
造诣不够,就只知道这么多了,欢迎各位大牛补充!
http://blog.youkuaiyun.com/vinomvp/article/details/52228377