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

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>

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值