Created
February 12, 2025 07:10
-
-
Save lgawin/56dd37fee2ca018e27b9e033a11e900e to your computer and use it in GitHub Desktop.
Util function (in Kotlin) to read android property (same as `adb shell getprop xxx`)
This file contains 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
@SuppressLint("PrivateApi") | |
fun getSystemProperty(propertyName: String) : String? = runCatching { | |
val clazz = Class.forName("android.os.SystemProperties") | |
val method = clazz.getMethod("get", String::class.java, String::class.java) | |
val value = method.invoke(clazz, propertyName, null) as String? | |
value | |
}.onFailure { Log.e("getSystemProperty", "failed to get: $propertyName", it) } | |
.getOrNull() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment