From 51759aa199d4259656107fa7c45c166cbb96160d Mon Sep 17 00:00:00 2001 From: LittleTurtle2333 Date: Mon, 27 Feb 2023 17:43:44 +0800 Subject: [PATCH] Update SystemProperties.kt --- .../simplicitytools/utils/SystemProperties.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 app/src/main/java/com/lt2333/simplicitytools/utils/SystemProperties.kt diff --git a/app/src/main/java/com/lt2333/simplicitytools/utils/SystemProperties.kt b/app/src/main/java/com/lt2333/simplicitytools/utils/SystemProperties.kt new file mode 100644 index 00000000..3106c511 --- /dev/null +++ b/app/src/main/java/com/lt2333/simplicitytools/utils/SystemProperties.kt @@ -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?> = arrayOfNulls(1) + paramTypes[0] = String::class.java + val get = systemProperties.getMethod("get", *paramTypes) + //参数 + val params = arrayOfNulls(1) + params[0] = key + ret = get.invoke(systemProperties, *params) as String + } catch (iAE: IllegalArgumentException) { + throw iAE + } catch (e: Exception) { + ret = "" + } + return ret + } + +} \ No newline at end of file