mirror of
https://github.com/LittleTurtle2333/SimplicityTools.git
synced 2026-07-12 11:21:18 +08:00
Update SystemProperties.kt
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
package com.lt2333.simplicitytools.utils
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
|
||||||
|
object SystemProperties {
|
||||||
|
@SuppressLint("PrivateApi")
|
||||||
|
operator fun get(context: Context, key: String?): String {
|
||||||
|
var ret = ""
|
||||||
|
try {
|
||||||
|
val cl = context.classLoader
|
||||||
|
val systemProperties = cl.loadClass("android.os.SystemProperties")
|
||||||
|
//参数类型
|
||||||
|
val paramTypes: Array<Class<*>?> = arrayOfNulls(1)
|
||||||
|
paramTypes[0] = String::class.java
|
||||||
|
val get = systemProperties.getMethod("get", *paramTypes)
|
||||||
|
//参数
|
||||||
|
val params = arrayOfNulls<Any>(1)
|
||||||
|
params[0] = key
|
||||||
|
ret = get.invoke(systemProperties, *params) as String
|
||||||
|
} catch (iAE: IllegalArgumentException) {
|
||||||
|
throw iAE
|
||||||
|
} catch (e: Exception) {
|
||||||
|
ret = ""
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user