赞
踩
最近项目中遇到这样个需求场景:
当我们的用户使用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);
- 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);
- 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);
- 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);
来源:http://www.itwendao.com/article/detail/396411.html点击打开链接
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。