Created
June 9, 2020 07:24
-
-
Save ivaniskandar/080d4269a63c966b60a103ce5d65526f to your computer and use it in GitHub Desktop.
Get device Samsung OneUI version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Context.getOneUiVersion(): Double { | |
if (!isSemAvailable()) { | |
return 1.0 | |
} | |
val semPlatformIntField: Field = Build.VERSION::class.java.getDeclaredField("SEM_PLATFORM_INT") | |
val version: Int = semPlatformIntField.getInt(null) - 90000 | |
return if (version < 0) { | |
1.0 | |
} else { | |
((version / 10000).toString() + "." + version % 10000 / 100).toDouble() | |
} | |
} | |
private fun Context.isSemAvailable(): Boolean { | |
return packageManager.hasSystemFeature("com.samsung.feature.samsung_experience_mobile") || | |
packageManager.hasSystemFeature("com.samsung.feature.samsung_experience_mobile_lite") | |
} |
nanggatal
commented
Sep 4, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment