一、代码
package com.xxx.bluetooth_ble.permission;import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.util.Log;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;public class JumpPermissionManagement {private Context mContext;private String TAG = "JumpPermissionManagement";//自己的项目包名private String packageName = "your-packageName(自己去清单文件看一下)";public JumpPermissionManagement(Context context) {this.mContext = context;}public void jumpPermissionPage() {try {String name = Build.MANUFACTURER;switch (name) {case "HUAWEI":goHuaWeiManager();break;case "vivo":goVivoManager();break;case "OPPO":goOppoManager();break;case "Coolpad":goCoolpadManager();break;case "Meizu":goMeiZuManager();break;case "Xiaomi":goXiaoMiMainager();break;case "samsung":goSangXinManager();break;case "Sony":goSonyManager();break;case "LG":goLGManager();break;default:goIntentSetting();break;}} catch (Exception e) {goIntentSetting();}}private void goLGManager() {try {Intent intent = new Intent(packageName);ComponentName comp = new ComponentName("com.android.settings", "com.android.settings.Settings$AccessLockSummaryActivity");intent.setComponent(comp);mContext.startActivity(intent);} catch (Exception e) {goIntentSetting();}}private void goSonyManager() {try {Intent intent = new Intent(packageName);ComponentName comp = new ComponentName("com.sonymobile.cta", "com.sonymobile.cta.SomcCTAMainActivity");intent.setComponent(comp);mContext.startActivity(intent);} catch (Exception e) {goIntentSetting();}}private void goHuaWeiManager() {try {Intent intent = new Intent(packageName);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);ComponentName comp = new ComponentName("com.huawei.systemmanager", "com.huawei.permissionmanager.ui.MainActivity");intent.setComponent(comp);mContext.startActivity(intent);} catch (Exception e) {goIntentSetting();}}private static String getMiuiVersion() {String propName = "ro.miui.ui.version.name";String line = null;BufferedReader input = null;try {Process p = Runtime.getRuntime().exec("getprop " + propName);input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);line = input.readLine();} catch (Exception ex) {//Timber.e(ex);} finally {if (input != null) {try {input.close();} catch (IOException e) {//Timber.e(e);}}}return line;}private void goXiaoMiMainager() {String rom = getMiuiVersion();Log.d(TAG,"getMiuiVersion:"+rom);Intent intent = new Intent();if ("V6".equals(rom) || "V7".equals(rom)) {intent.setAction("miui.intent.action.APP_PERM_EDITOR");intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");intent.putExtra("extra_pkgname", packageName);} else if ("V8".equals(rom) || "V9".equals(rom)) {intent.setAction("miui.intent.action.APP_PERM_EDITOR");intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");intent.putExtra("extra_pkgname", packageName);} else if ("V130".equals(rom)){intent= new Intent("miui.intent.action.APP_PERM_EDITOR");intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");intent.putExtra("extra_pkgname", mContext.getPackageName());}elsegoIntentSetting();mContext.startActivity(intent);}private void goMeiZuManager() {try {Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");intent.addCategory(Intent.CATEGORY_DEFAULT);intent.putExtra("packageName", packageName);mContext.startActivity(intent);} catch (ActivityNotFoundException localActivityNotFoundException) {localActivityNotFoundException.printStackTrace();goIntentSetting();}}private void goSangXinManager() {//三星4.3可以直接跳转goIntentSetting();}private void goIntentSetting() {Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);Uri uri = Uri.fromParts("package", mContext.getPackageName(), null);intent.setData(uri);try {mContext.startActivity(intent);} catch (Exception e) {//Timber.e(e);}}private void goOppoManager() {doStartApplicationWithPackageName("com.coloros.safecenter");}/*** doStartApplicationWithPackageName("com.yulong.android.security:remote")* 和Intent open = getPackageManager().getLaunchIntentForPackage("com.yulong.android.security:remote");* startActivity(open);* 本质上没有什么区别,通过Intent open...打开比调用doStartApplicationWithPackageName方法更快,也是android本身提供的方法*/private void goCoolpadManager() {doStartApplicationWithPackageName("com.yulong.android.security:remote");/* Intent openQQ = getPackageManager().getLaunchIntentForPackage("com.yulong.android.security:remote");startActivity(openQQ);*/}private void goVivoManager() {doStartApplicationWithPackageName("com.bairenkeji.icaller");/* Intent openQQ = getPackageManager().getLaunchIntentForPackage("com.vivo.securedaemonservice");startActivity(openQQ);*/}/*** 此方法在手机各个机型设置中已经失效** @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", 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());}return localIntent;}private void doStartApplicationWithPackageName(String packagename) {// 通过包名获取此APP详细信息,包括Activities、services、versioncode、name等等PackageInfo packageinfo = null;try {packageinfo = mContext.getPackageManager().getPackageInfo(packagename, 0);} catch (PackageManager.NameNotFoundException e) {//Timber.e(e);}if (packageinfo == null) {return;}try {// 创建一个类别为CATEGORY_LAUNCHER的该包名的IntentIntent resolveIntent = new Intent(Intent.ACTION_MAIN, null);resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);resolveIntent.setPackage(packageinfo.packageName);// 通过getPackageManager()的queryIntentActivities方法遍历List<ResolveInfo> resolveinfoList = mContext.getPackageManager().queryIntentActivities(resolveIntent, 0);ResolveInfo resolveinfo = resolveinfoList.iterator().next();if (resolveinfo != null) {// packageName参数2 = 参数 packnameString packageName = resolveinfo.activityInfo.packageName;// 这个就是我们要找的该APP的LAUNCHER的Activity[组织形式:packageName参数2.mainActivityname]String className = resolveinfo.activityInfo.name;// LAUNCHER IntentIntent intent = new Intent(Intent.ACTION_MAIN);intent.addCategory(Intent.CATEGORY_LAUNCHER);// 设置ComponentName参数1:packageName参数2:MainActivity路径ComponentName cn = new ComponentName(packageName, className);intent.setComponent(cn);mContext.startActivity(intent);}} catch (Exception e) {goIntentSetting();}}
}
二、调用的地方
JumpPermissionManagement m_JumpPermissionManagement = new JumpPermissionManagement(m_context);
m_JumpPermissionManagement.jumpPermissionPage();
三、三星手机的界面
四、小米平板
1、打开settings里面的该app的权限界面,执行
dumpsys activity | grep mFocusedApp
2、跳转的地方代码
private void goXiaoMiMainager() {String rom = getMiuiVersion();Log.d(TAG,"getMiuiVersion:"+rom);Intent intent = new Intent();if ("V6".equals(rom) || "V7".equals(rom)) {intent.setAction("miui.intent.action.APP_PERM_EDITOR");intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");intent.putExtra("extra_pkgname", packageName);} else if ("V8".equals(rom) || "V9".equals(rom)) {intent.setAction("miui.intent.action.APP_PERM_EDITOR");intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");intent.putExtra("extra_pkgname", packageName);} else if ("V130".equals(rom)){intent= new Intent("miui.intent.action.APP_PERM_EDITOR");intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");intent.putExtra("extra_pkgname", mContext.getPackageName());}elsegoIntentSetting();mContext.startActivity(intent);}
3、效果
五、参考文章
Android调用miui给权限,Android跳转至MIUI权限设置页面_喝冰红茶的虫的博客-CSDN博客
Android兼容适配 - 不同机型跳转应用权限设置页面_android跳转应用权限设置_Modu_Liu的博客-CSDN博客