【发布时间】:2018-08-14 11:22:56
【问题描述】:
对于 Android P,非 SDK 接口已被弃用。 (链接:https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces) 在我们的旧代码中,我们通过以下方式使用“android.os.SystemProperties”,
String countryCode = null;
try
{
Class<?> cl;
cl = Class.forName("android.os.SystemProperties");
Method method = cl.getDeclaredMethod("get", String.class);
countryCode = (String) method.invoke(null, "ro.csc.countryiso_code");
return
}
由于我们不能再以这种方式使用它,我现在尝试通过以下方式获得相同的值,
String propertyValue = "";
BufferedReader reader = null;
Process process = Runtime.getRuntime().exec("getprop " + key);
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
propertyValue = reader.readLine().trim();
虽然这是一种标准方式,但速度非常慢,正如您所见,它正在创建一个新进程,然后运行 shell 命令 getprop 等等。 我的问题是,有没有更好的方法来获取这些属性?
【问题讨论】:
标签: android android-ndk