Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

like image 936
Sagar Makhija Avatar asked Jul 11 '17 10:07

Sagar Makhija


1 Answers

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.

like image 150
Sonu Kumar Avatar answered Sep 27 '22 22:09

Sonu Kumar