How to get Permission for read “Service SMS” in MI

2019-02-10 11:01发布

How to get Permission for read "Service SMS" in MIUI 8+ (programmatically).

How to get Permission for read "Service SMS" in MIUI 8+ (programmatically)

1条回答
小情绪 Triste *
2楼-- · 2019-02-10 11:34

This will launch the intent for service sms. Once user will allow the access for service sms you will able to read the notification sms.

if (isMIUI()) {
            //this will launch the auto start screen where user can enable the permission for your app
      Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
                    localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
      localIntent.putExtra("extra_pkgname", getActivity().getPackageName());
      startActivity(localIntent);
}


 public static boolean isMIUI() {
        String device = Build.MANUFACTURER;
        if (device.equals("Xiaomi")) {
            try {
                Properties prop = new Properties();
                prop.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
                return prop.getProperty("ro.miui.ui.version.code", null) != null
                        || prop.getProperty("ro.miui.ui.version.name", null) != null
                        || prop.getProperty("ro.miui.internal.storage", null) != null;
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

         return false;
  }

Note: you can not take the permission programmatically it's only allowed for whitelisted app from MIUI. for example- facebook messenger, whatsapp, flipkart etc have autostart option by default.

查看更多
登录 后发表回答