roiberg
roiberg

Reputation: 13737

Tell if device is running a MIUI software

I need to know if my app is running on a MIUI device like XIAOMI at runtime due to issues like pre android 6.0 permissions etc.

Is there a way to to do it?

Upvotes: 5

Views: 2844

Answers (2)

Jonathan F.
Jonathan F.

Reputation: 2364

Kotlin version here with ability to check both miUi and HyperOS :

https://gist.github.com/starry-shivam/901267c26eb030eb3faf1ccd4d2bdd32

(all credits to starry-shivam)

Upvotes: 0

Gil Fidel
Gil Fidel

Reputation: 156

I've found a gist on github that aims to do just that, by trying to fetch the "ro.miui.ui.version.name" system property.

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

Upvotes: 14

Related Questions