Skip to content

Instantly share code, notes, and snippets.

@starry-shivam
Last active February 10, 2026 02:15
Show Gist options
  • Select an option

  • Save starry-shivam/901267c26eb030eb3faf1ccd4d2bdd32 to your computer and use it in GitHub Desktop.

Select an option

Save starry-shivam/901267c26eb030eb3faf1ccd4d2bdd32 to your computer and use it in GitHub Desktop.

Revisions

  1. starry-shivam revised this gist May 24, 2024. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions MiuiCheck.kt
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,9 @@ object MiuiCheck {
    * @return True if the device is running on MIUI, false otherwise
    */
    fun isMiui(excludeHyperOS: Boolean = true): Boolean {
    // Check if the device is manufactured by Xiaomi, Redmi, or POCO.
    val brand = Build.BRAND.lowercase()
    if (!setOf("xiaomi", "redmi", "poco").contains(brand)) return false
    // This property is present in both MIUI and HyperOS.
    val isMiui = !getProperty("ro.miui.ui.version.name").isNullOrBlank()
    // This property is exclusive to HyperOS only and isn't present in MIUI.
  2. starry-shivam created this gist May 12, 2024.
    31 changes: 31 additions & 0 deletions MiuiCheck.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    object MiuiCheck {

    /**
    * Check if the device is running on MIUI.
    *
    * By default, HyperOS is excluded from the check.
    * If you want to include HyperOS in the check, set excludeHyperOS to false.
    *
    * @param excludeHyperOS Whether to exclude HyperOS
    * @return True if the device is running on MIUI, false otherwise
    */
    fun isMiui(excludeHyperOS: Boolean = true): Boolean {
    // This property is present in both MIUI and HyperOS.
    val isMiui = !getProperty("ro.miui.ui.version.name").isNullOrBlank()
    // This property is exclusive to HyperOS only and isn't present in MIUI.
    val isHyperOS = !getProperty("ro.mi.os.version.name").isNullOrBlank()
    return isMiui && (!excludeHyperOS || !isHyperOS)
    }

    // Private function to get the property value from build.prop.
    private fun getProperty(property: String): String? {
    return try {
    Runtime.getRuntime().exec("getprop $property").inputStream.use { input ->
    BufferedReader(InputStreamReader(input), 1024).readLine()
    }
    } catch (e: IOException) {
    e.printStackTrace()
    null
    }
    }
    }