Android Properties使用

java

  • 该API上层应用无法直接使用,可以通过反射,或者导入framework.jar来使用
import android.os.SystemProperties;

SystemProperties.set("persist.lock","true")
String lock = SystemProperties.get("persist.lock")
boolean lock = SystemProperties.getBoolean("persist.lock", false)

C++

#include <cutils/properties.h>
Android.mk 中添加 LOCAL_STATIC_LIBRARIES :=libcutils

int property_get(const char *key, char *value, const char *default_value);
int property_set(const char *key, const char *value);
int property_list....
-----------------------
char prop[PROPERTY_VALUE_MAX]="false";
if(property_get("persist.lock",prop,"false")!=0){
    ....
}

shell命令设置属性

getprop persist.lock
setprop persist.lock false

其它知识

  • 长度限制
#define PROPERTY_KEY_MAX   32   //KEY值
#define PROPERTY_VALUE_MAX  92  //VALUE值
posted @   天天敲代码身体棒  阅读(83)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示