【问题标题】:Tell if device is running a MIUI software判断设备是否正在运行 MIUI 软件
【发布时间】:2018-01-29 05:09:43
【问题描述】:

由于 pre android 6.0 权限等问题,我需要知道我的应用程序是否在运行时在 MIUI 设备(如 XIAOMI)上运行。

有什么办法吗?

【问题讨论】:

    标签: android runtime-permissions miui


    【解决方案1】:

    我在 github 上找到了一个旨在做到这一点的要点,方法是尝试获取“ro.miui.ui.version.name”系统属性。

    public static boolean isMiUi() {
        return !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.name"));
    }
    
    public static String getSystemProperty(String propName) {
        String line;
        BufferedReader input = null;
        try {
            java.lang.Process p = Runtime.getRuntime().exec("getprop " + propName);
            input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
            line = input.readLine();
            input.close();
        } catch (IOException ex) {
            return null;
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return line;
    }
    

    Origin on github

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 1970-01-01
      • 2011-10-31
      相关资源
      最近更新 更多