如何获得阅读“服务短信"的权限在 MIUI 8+ 中(以编程方式) [英] How to get Permission for read "Service SMS" in MIUI 8+ (programmatically)

查看:17
本文介绍了如何获得阅读“服务短信"的权限在 MIUI 8+ 中(以编程方式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得在 MIUI 8+ 中读取服务短信"的权限(以编程方式).

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

推荐答案

这将启动服务短信的意图.一旦用户允许访问服务短信,您就可以阅读通知短信.

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;
  }

注意:您不能以编程方式获取权限,它只允许来自 MIUI 的白名单应用程序.例如 - facebook messenger、whatsapp、flipkart 等默认有自动启动选项.

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.

这篇关于如何获得阅读“服务短信"的权限在 MIUI 8+ 中(以编程方式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆