Android adb 设置和获取系统属性

/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>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容