android各大手机系统打开权限管理页面

来源:互联网 发布:数据分析笔试题及答案 编辑:程序博客网 时间:2024/04/29 04:26

最近项目上比较忙,终于有空闲时间写写东西了。

相信做过Android的都知道,现在的手机系统五花八门,当我们去请求用户的权限的时候,总是会弹出是否允许的对话框。

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

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

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

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

不多说,直接上代码。

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

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


[java] view plain copy
  1. /** 
  2.  * 跳转到miui的权限管理页面 
  3.  */  
  4. private void gotoMiuiPermission() {  
  5.     Intent i = new Intent("miui.intent.action.APP_PERM_EDITOR");  
  6.     ComponentName componentName = new ComponentName("com.miui.securitycenter""com.miui.permcenter.permissions.AppPermissionsEditorActivity");  
  7.     i.setComponent(componentName);  
  8.     i.putExtra("extra_pkgname", getPackageName());  
  9.     try {  
  10.         startActivity(i);  
  11.     } catch (Exception e) {  
  12.         e.printStackTrace();  
  13.         gotoMeizuPermission();  
  14.     }  
  15. }  

接下来上魅族的代码


[java] view plain copy
  1. /** 
  2.  * 跳转到魅族的权限管理系统 
  3.  */  
  4. private void gotoMeizuPermission() {  
  5.     Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");  
  6.     intent.addCategory(Intent.CATEGORY_DEFAULT);  
  7.     intent.putExtra("packageName", BuildConfig.APPLICATION_ID);  
  8.     try {  
  9.         startActivity(intent);  
  10.     } catch (Exception e) {  
  11.         e.printStackTrace();  
  12.         gotoHuaweiPermission();  
  13.     }  
  14. }  

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

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

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


[java] view plain copy
  1. /** 
  2.  * 华为的权限管理页面 
  3.  */  
  4. private void gotoHuaweiPermission() {  
  5.     try {  
  6.         Intent intent = new Intent();  
  7.         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  8.         ComponentName comp = new ComponentName("com.huawei.systemmanager""com.huawei.permissionmanager.ui.MainActivity");//华为权限管理  
  9.         intent.setComponent(comp);  
  10.         startActivity(intent);  
  11.     } catch (Exception e) {  
  12.         e.printStackTrace();  
  13.         startActivity(getAppDetailSettingIntent());  
  14.     }  
  15.   
  16. }  

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


[java] view plain copy
  1. /** 
  2.  * 获取应用详情页面intent 
  3.  * 
  4.  * @return 
  5.  */  
  6. private Intent getAppDetailSettingIntent() {  
  7.     Intent localIntent = new Intent();  
  8.     localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  9.     if (Build.VERSION.SDK_INT >= 9) {  
  10.         localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");  
  11.         localIntent.setData(Uri.fromParts("package", getPackageName(), null));  
  12.     } else if (Build.VERSION.SDK_INT <= 8) {  
  13.         localIntent.setAction(Intent.ACTION_VIEW);  
  14.         localIntent.setClassName("com.android.settings""com.android.settings.InstalledAppDetails");  
  15.         localIntent.putExtra("com.android.settings.ApplicationPkgName", getPackageName());  
  16.     }  
  17.     return localIntent;  
  18. }  

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

造诣不够,就只知道这么多了,欢迎各位大牛补充!

0 0
原创粉丝点击