系统属性
说明:
开发前请熟悉鸿蒙开发指导文档 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]
导入模块
import parameter from '@ohos.systemParameter'
parameter.getSync
getSync(key: string, def?: string): string
获取系统属性Key对应的值。
系统能力: SystemCapability.Startup.SysInfo
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| key | string | 是 | 待查询的系统属性Key。 |
| def | string | 否 | 默认值。 |
返回值:
| 类型 | 说明 |
|---|---|
| string | 系统属性值,若key不存在,返回默认值。若未指定默认值,返回空字符串。 |
示例:
try {
var info = parameter.getSync("test.parameter.key");
console.log(JSON.stringify(info));
}catch(e){
console.log("getSync unexpected error: " + e);
}
parameter.get
get(key: string, callback: AsyncCallback): void
获取系统属性Key对应的值。
系统能力: SystemCapability.Startup.SysInfo
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| key | string | 是 | 待查询的系统属性Key。 |
| callback | AsyncCallback | 是 | 回调函数。 |
示例:
try {
parameter.get("test.parameter.key", function (err, data) {
if (err == undefined) {
console.log("get test.parameter.key value success:" + data)
} else {
console.log(" get test.parameter.key value err:" + err.code)
}});
}catch(e){
console.log("get unexpected error: " + e);
}
parameter.get
get(key: string, def: string, callback: AsyncCallback): void
获取系统属性Key对应的值。
系统能力: SystemCapability.Startup.SysInfo
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| key | string | 是 | 待查询的系统属性Key。 |
| def | string | 是 | 默认值。 |
| callback | AsyncCallback | 是 | 回调函数。 |
示例:
try {
parameter.get("test.parameter.key", "default", function (err, data) {
if (err == undefined) {
console.log("get test.parameter.key value success:" + data)
} else {
console.log(" get test.parameter.key value err:" + err.code)
}
});
}catch(e){
console.log("get unexpected error:" + e)
}
parameter.get
get(key: string, def?: string): Promise
获取系统属性Key对应的值。
系统能力: SystemCapability.Startup.SysInfo
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| key | string | 是 | 待查询的系统属性Key。 |
| def | string | 否 | 默认值。 |
返回值:
| 类型 | 说明 |
|---|---|
| Promise | Promise示例,用于异步获取结果。 |
示例:
try {
var p = parameter.get("test.parameter.key");
p.then(function (value) {
console.log("get test.parameter.key success: " + value);
}).catch(function (err) {
console.log("get test.parameter.key error: " + err.code);
});
}catch(e){
console.log("get unexpected error: " + e);
}
parameter.setSync
setSync(key: string, value: string): void
设置系统属性Key对应的值。
系统能力: SystemCapability.Startup.SysInfo
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| key | string | 是 | 待设置的系统属性Key。 |
| value | string | 是 | 待设置的系统属性值。 |
示例:
try {
parameter.setSync("test.parameter.key", "default");
}catch(e){
console.log("set unexpected error: " + e);
}
parameter.set
set(key: string, value: string, callback: AsyncCallback): void
设置系统属性Key对应的值。
系统能力: SystemCapability.Startup.SysInfo
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| key | string | 是 | 待设置的系统属性Key。 |
| value | string | 是 | 待设置的系统属性值。 |
| callback | AsyncCallback | 是 | 回调函数。 |
示例:
try {
parameter.set("test.parameter.key", "testValue", function (err, data) {
if (err == undefined) {
console.log("set test.parameter.key value success :" + data)
} else {
console.log("set test.parameter.key value err:" + err.code)
}});
}catch(e){
console.log("set unexpected error: " + e);
}
parameter.set
set(key: string, value: string): Promise
设置系统属性Key对应的值。
系统能力: SystemCapability.Startup.SysInfo
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| key | string | 是 | 待待设置的系统属性Key。 |
| value | string | 否 | 待设置的系统属性值。 |
返回值:
| 类型 | 说明HarmonyOS与OpenHarmony鸿蒙文档籽料:mau123789是v直接拿 |
|---|---|
| Promise | Promise示例,用于异步获取结果。 |
示例:
try {
var p = para.set("test.parameter.key", "testValue");
p.then(function (value) {
console.log("set test.parameter.key success: " + value);
}).catch(function (err) {
console.log(" set test.parameter.key error: " + err.code);
});
}catch(e){
console.log("set unexpected error: " + e);
}
审核编辑 黄宇
-
鸿蒙
+关注
关注
60文章
2853浏览量
45340
发布评论请先 登录
为什么系统属性中显示的系统内存会有不同?
设备管理系统软件有哪些
整理公共基础库子系统和系统属性组件
【触觉智能 Purple Pi OH 开发板体验】修改OpenHarmony 设备厂家名称 、硬件版本号 等系统属性详细步骤
面向预测性维护的制造工业设备管理系统
鸿蒙开发设备管理:ohos.multimodalInput.inputDevice 输入设备
设备管理系统,终结设备管理难题

鸿蒙开发设备管理:ohos.systemParameter 系统属性
说明:
评论