Wednesday, July 30, 2014

How to check whether device is running CyanogenMod in Android

Today, I wanted to know how to detect whether device is running CyanogenMod. System.getProperty("os.version") used to return cyanogenmod however it is not the case when i checked it today. CyanogenMod. System.getProperty("os.version")  was returning something like 3.0.64-CM-g9d16c8a. So I wrote this function. Hope it will be use full for someone else.

private boolean isCyanogenMod(PackageManager pm) {
    boolean isCyanogenMod = false;
    String version = System.getProperty("os.version");
    BufferedReader reader = null;

    try {
        if (version.contains("cyanogenmod") || pm.hasSystemFeature("com.cyanogenmod.android")) {
            isCyanogenMod = true;
        }
        else {                
            // This does not require root
            reader = new BufferedReader(new FileReader("/proc/version"), 256);
            version = reader.readLine();

            if (version.contains("cyanogenmod")) {
                isCyanogenMod = true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        if(reader != null) {
            try { reader.close(); } catch (IOException e) { }
        }
    }

    return isCyanogenMod;
}



No comments:

Post a Comment