The Solution of Refusing to Open the User Interface of Permission Setting over Android 6.0

  • 2021-09-24 23:44:57
  • OfStack

When I use Xiaomi mobile phone to open qq or WeChat, if a certain permission is rejected, I will prompt you to open it. Clicking Open will jump to the permission setting interface of app. Of course, this is the reason for deep customization of domestic systems, that is to say, android of the original sound of this interface does not have it! Here, Xiaomi and Meizu are used as examples to explain how to let users manually open permissions. Of course, if it is the original android, let him jump to the application details setting page (a little pit, because ordinary users still don't know how to adjust it).

Reference to a lot of bits and pieces of things, the website has been unable to find. . . . . .

ok, the first step is to jump to the interface of the system, the following can basically be considered from 9, which can be simplified.


String SCHEME = "package";
  // Calling system InstalledAppDetails Required by the interface Extra Name ( Used for Android 2.1 And previous versions )
  final String APP_PKG_NAME_21 = "com.android.settings.ApplicationPkgName";
  // Calling system InstalledAppDetails Required by the interface Extra Name ( Used for Android 2.2)
  final String APP_PKG_NAME_22 = "pkg";
  //InstalledAppDetails Package name 
  final String APP_DETAILS_PACKAGE_NAME = "com.android.settings";
  //InstalledAppDetails Class name 
  final String APP_DETAILS_CLASS_NAME = "com.android.settings.InstalledAppDetails";
 
  Intent intent = new Intent();
  final int apiLevel = Build.VERSION.SDK_INT;
  if (apiLevel >= 9) { // 2.3 ( ApiLevel 9 ) above, using SDK Provided interface 
   intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
   Uri uri = Uri.fromParts(SCHEME, getPackageName(), null);
   intent.setData(uri);
  } else { // 2.3 Below, use a non-public interface (see InstalledAppDetails Source code) 
   // 2.2 And 2.1 In, InstalledAppDetails Used APP_PKG_NAME Different. 
   final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22
     : APP_PKG_NAME_21);
   intent.setAction(Intent.ACTION_VIEW);
   intent.setClassName(APP_DETAILS_PACKAGE_NAME,
     APP_DETAILS_CLASS_NAME);
   intent.putExtra(appPkgName, getPackageName());
  }
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  startActivity(intent);

Second, miui, first you have to judge is miui, personally test, MIUI7 stable version, MIUI8 development board is feasible, tool class below will provide download


if (CheckPhoneSystemUtils.isMIUI()) {
   MLog.i(" Products / Xiaomi, the manufacturer of hardware :");
   intent.setAction("miui.intent.action.APP_PERM_EDITOR");
   intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
   intent.putExtra("extra_pkgname", getPackageName());
   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   try {
    startActivity(intent);
   } catch (Exception e) {
    e.printStackTrace();
    Toast.makeText(MediaRecoderService.this, " Only MIUI You can set it up ", Toast.LENGTH_SHORT).show();
   }
  }

The third, flyme (because there is no flyme machine), is tested by cloud mobile phone


else if (CheckPhoneSystemUtils.isFlyme()) {
   intent.setAction("com.meizu.safe.security.SHOW_APPSEC");
   intent.addCategory(Intent.CATEGORY_DEFAULT);
   intent.putExtra("packageName", getPackageName());
   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   try {
    startActivity(intent);
   } catch (Exception e) {
    e.printStackTrace();
    Toast.makeText(MediaRecoderService.this, " Only Flyme You can set it up ", Toast.LENGTH_SHORT).show();
   }
  } 

The following is the tool class: BuildProperties


public class BuildProperties {
 private final Properties properties;
 
 private BuildProperties() throws IOException {
  properties = new Properties();
  properties.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
 }
 
 public boolean containsKey(final Object key) {
  return properties.containsKey(key);
 }
 
 public boolean containsValue(final Object value) {
  return properties.containsValue(value);
 }
 
 public Set<Map.Entry<Object, Object>> entrySet() {
  return properties.entrySet();
 }
 
 public String getProperty(final String name) {
  return properties.getProperty(name);
 }
 
 public String getProperty(final String name, final String defaultValue) {
  return properties.getProperty(name, defaultValue);
 }
 
 public boolean isEmpty() {
  return properties.isEmpty();
 }
 
 public Enumeration<Object> keys() {
  return properties.keys();
 }
 
 public Set<Object> keySet() {
  return properties.keySet();
 }
 
 public int size() {
  return properties.size();
 }
 
 public Collection<Object> values() {
  return properties.values();
 }
 
 public static BuildProperties newInstance() throws IOException {
  return new BuildProperties();
 }

CheckPhoneSystemUtils


 private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
 private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
 private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage";
 
 /**
  *  Detection MIUI
  *
  * @return
  */
 public static boolean isMIUI() {
  try {
   final BuildProperties prop = BuildProperties.newInstance();
   return prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null || prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null || prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null;
  } catch (final IOException e) {
   return false;
  }
 }
 
 /**
  *  Detection Flyme
  *
  * @return
  */
 public static boolean isFlyme() {
  try { // Invoke Build.hasSmartBar()
   final Method method = Build.class.getMethod("hasSmartBar");
   return method != null;
  } catch (final Exception e) {
   return false;
  }
 }

Related articles: