配套系列教学视频链接:
说明
系统:Android10.0
设备: FireFly RK3399 (ROC-RK3399-PC-PLUS)
前言
前面几篇文章介绍的属性基本框架和属性的基本概念, 在Android中,各种代码场景下都会对属性进行代码操作, 所以需要了解一下常见的C, C++,java中属性的各种API。
一, API调用层次

二, C语言客户端API
头文件在: system/core/include/cutils/properties.h
实现在: system/core/libcutils/properties.cpp
int8_t property_get_bool(const char *key, int8_t default_value);
int64_t property_get_int64(const char *key, int64_t default_value);
int property_get(const char* key, char* value, const char* default_value);
int32_t property_get_int32(const char *key, int32_t default_value);
int property_set(const char *key, const char *value);
例子:
#include <cutils/properties.h>
#include <log/log.h>
property_set("persist.sys.language", "zh");
property_get("persist.sys.language", propLang, "en");
三, C++客户端API
头文件声明在: system/core/base/include/android-base/properties.h
实现代: system/core/base/properties.cpp
namespace android {
namespace base {
// 获取bool类型的属性值,如果属性为空或者不存在, 返回参数2的默认值
bool GetBoolProperty(const std::str

本文详细介绍了安卓系统开发中,如何通过C、C++和Java的API操作系统属性,包括client API、服务端实现、JAVAAPI以及关键系统的属性获取与设置。涵盖了头文件、函数示例和系统属性获取类的使用方法。

1072

被折叠的 条评论
为什么被折叠?



