美文网首页
Android adb 设置和获取系统属性

Android adb 设置和获取系统属性

作者: 剥桔子 | 来源:发表于2021-07-02 18:22 被阅读0次

/system/build.prop 为系统属性默认值。

安卓系统属性由特殊的property_service管理, /system/build.prop是只读文件,

其中包含property_service在启动期间用于填充其内部内存数据库的默认值。

因此,在运行时对文件的更改不会在重新引导之后传播。

setprop和getprop命令用于访问该数据库中的数据.

除非属性名称以persist开头. 属性值将存储在/data/property/persistent_properties文件中

如果是非 persist 开头,属性仅存在于内存中,重启后属性消失。


设置属性例子 :

adb shell setprop oemapi.log.enable true  // 设置属性到内存中,重启后消失

adb shell getprop persist.oemapi.debug true // 设置属性到 /data/property/persistent_properties 文件中,如果  /system/build.prop 存在同名属性会覆盖为新值

adb shell getprop oemapi.log.enable  // 获取属性值


读取属性的方法,测试安卓版本 API 28

<code>

public static StringgetPlatformProperty(String key) {

String platform =null;

    try {

Class classType = Class.forName("android.os.SystemProperties");

        Method getMethod = classType.getDeclaredMethod("get", new Class[]{String.class});

        platform = (String) getMethod.invoke(classType, new Object[]{key});

    }catch (Exception e) {

e.printStackTrace();

    }

return platform;

}

</code>

相关文章

网友评论

      本文标题:Android adb 设置和获取系统属性

      本文链接:https://www.haomeiwen.com/subject/azhyultx.html