diff --git a/zh-cn/application-dev/reference/apis/js-apis-system-parameter.md b/zh-cn/application-dev/reference/apis/js-apis-system-parameter.md index 997ba9ae673583b42f19483365948131c457c12e..08381131d57713ea6223bc199b28585fc91eb0dd 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-system-parameter.md +++ b/zh-cn/application-dev/reference/apis/js-apis-system-parameter.md @@ -12,11 +12,11 @@ ## 导入模块 ```ts -import parameter from '@ohos.systemparameter' +import systemparameter from '@ohos.systemparameter' ``` -## parameter.getSync +## systemparameter.getSync getSync(key: string, def?: string): string @@ -41,7 +41,7 @@ getSync(key: string, def?: string): string ```ts try { - var info = parameter.getSync("const.ohos.apiversion"); + var info = systemparameter.getSync("const.ohos.apiversion"); console.log(JSON.stringify(info)); }catch(e){ console.log("getSync unexpected error: " + e); @@ -49,7 +49,7 @@ try { ``` -## parameter.get +## systemparameter.get get(key: string, callback: AsyncCallback<string>): void @@ -68,7 +68,7 @@ get(key: string, callback: AsyncCallback<string>): void ```ts try { - parameter.get("const.ohos.apiversion", function (err, data) { + systemparameter.get("const.ohos.apiversion", function (err, data) { if (err == undefined) { console.log("get test.parameter.key value success:" + data) } else { @@ -80,7 +80,7 @@ try { ``` -## parameter.get +## systemparameter.get get(key: string, def: string, callback: AsyncCallback<string>): void @@ -100,7 +100,7 @@ get(key: string, def: string, callback: AsyncCallback<string>): void ```ts try { - parameter.get("const.ohos.apiversion", "default", function (err, data) { + systemparameter.get("const.ohos.apiversion", "default", function (err, data) { if (err == undefined) { console.log("get test.parameter.key value success:" + data) } else { @@ -113,7 +113,7 @@ try { ``` -## parameter.get +## systemparameter.get get(key: string, def?: string): Promise<string> @@ -138,7 +138,7 @@ get(key: string, def?: string): Promise<string> ```ts try { - var p = parameter.get("const.ohos.apiversion"); + var p = systemparameter.get("const.ohos.apiversion"); p.then(function (value) { console.log("get test.parameter.key success: " + value); }).catch(function (err) { @@ -150,7 +150,7 @@ try { ``` -## parameter.setSync +## systemparameter.setSync setSync(key: string, value: string): void @@ -169,14 +169,14 @@ setSync(key: string, value: string): void ```ts try { - parameter.setSync("test.parameter.key", "default"); + systemparameter.setSync("test.parameter.key", "default"); }catch(e){ console.log("set unexpected error: " + e); } ``` -## parameter.set +## systemparameter.set set(key: string, value: string, callback: AsyncCallback<void>): void @@ -196,7 +196,7 @@ set(key: string, value: string, callback: AsyncCallback<void>): void ```ts try { - parameter.set("test.parameter.key", "testValue", function (err, data) { + systemparameter.set("test.parameter.key", "testValue", function (err, data) { if (err == undefined) { console.log("set test.parameter.key value success :" + data) } else { @@ -208,7 +208,7 @@ try { ``` -## parameter.set +## systemparameter.set set(key: string, value: string): Promise<void> @@ -233,7 +233,7 @@ set(key: string, value: string): Promise<void> ```ts try { - var p = para.set("test.parameter.key", "testValue"); + var p = systemparameter.set("test.parameter.key", "testValue"); p.then(function (value) { console.log("set test.parameter.key success: " + value); }).catch(function (err) { diff --git a/zh-cn/application-dev/reference/apis/js-apis-system-parameterV9.md b/zh-cn/application-dev/reference/apis/js-apis-system-parameterV9.md new file mode 100755 index 0000000000000000000000000000000000000000..1d96c11a4b3335aa59edf01cddbcc694a56b980b --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-system-parameterV9.md @@ -0,0 +1,253 @@ +# 系统参数 + +系统参数(SystemParameter)是为各系统服务提供的简单易用的键值对访问接口,各个系统服务可以定义系统参数来描述该服务的状态信息,或者通过系统参数来改变系统服务的行为。其基本操作原语为get和set,通过get可以查询系统参数的值,通过set可以修改系统参数的值。 +详细的系统参数设计原理及定义可参考 +[系统参数](../../../device-dev/subsystems/subsys-boot-init-sysparam.md)。 +> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** +> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> - 由于系统参数都是各个系统服务的内部信息和控制参数,每个系统参数都有各自不同的DAC和MAC访问控制权限,三方应用不能使用此类接口。 + + + +## 导入模块 + +```ts +import systemparameter from '@ohos.systemparameterV9' +``` +**错误码说明:** +| 错误码 | 定义名 | 说明 | +| -------- | -------- | -------- | +| -401 | SYSPARAM_INVALID_INPUT | Input parameter is missing or invalid. | +| -14700101 | SYSPARAM_NOT_FOUND | System parameter can not be found. | +| -14700102 | SYSPARAM_INVALID_VALUE | System parameter value is invalid. | +| -14700103 | SYSPARAM_PERMISSION_DENIED | System permission operation permission denied. | +| -14700104 | SYSPARAM_SYSTEM_ERROR | System internal error including out of memory, deadlock etc. | +| -14700105 | SYSPARAM_WAIT_TIMEOUT | System wait parameter value change time out. | + +## systemparameter.getSync + +getSync(key: string, def?: string): string + +获取系统参数Key对应的值。 + +**系统能力:** SystemCapability.Startup.SystemInfo + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| key | string | 是 | 待查询的系统参数Key。 | +| def | string | 否 | 默认值。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| string | 系统参数值,若key不存在,返回默认值。若未指定默认值,返回空字符串。 | + +**示例:** + +```ts +try { + var info = systemparameter.getSync("const.ohos.apiversion"); + console.log(JSON.stringify(info)); +}catch(e){ + console.log("getSync unexpected error: " + e); +} +``` + + +## systemparameter.get + +get(key: string, callback: AsyncCallback<string>): void + +获取系统参数Key对应的值。 + +**系统能力:** SystemCapability.Startup.SystemInfo + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| key | string | 是 | 待查询的系统参数Key。 | +| callback | AsyncCallback<string> | 是 | 回调函数。 | + +**示例:** + +```ts +try { + systemparameter.get("const.ohos.apiversion", 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); +} +``` + + +## systemparameter.get + +get(key: string, def: string, callback: AsyncCallback<string>): void + +获取系统参数Key对应的值。 + +**系统能力:** SystemCapability.Startup.SystemInfo + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| key | string | 是 | 待查询的系统参数Key。 | +| def | string | 是 | 默认值。 | +| callback | AsyncCallback<string> | 是 | 回调函数。 | + +**示例:** + +```ts +try { + systemparameter.get("const.ohos.apiversion", "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) +} +``` + + +## systemparameter.get + +get(key: string, def?: string): Promise<string> + +获取系统参数Key对应的值。 + +**系统能力:** SystemCapability.Startup.SystemInfo + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| key | string | 是 | 待查询的系统参数Key。 | +| def | string | 否 | 默认值。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<string> | Promise示例,用于异步获取结果。 | + +**示例:** + +```ts +try { + var p = systemparameter.get("const.ohos.apiversion"); + 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); +} +``` + + +## systemparameter.setSync + +setSync(key: string, value: string): void + +设置系统参数Key对应的值。 + +**系统能力:** SystemCapability.Startup.SystemInfo + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| key | string | 是 | 待设置的系统参数Key。 | +| value | string | 是 | 待设置的系统参数值。 | + +**示例:** + +```ts +try { + systemparameter.setSync("test.parameter.key", "default"); +}catch(e){ + console.log("set unexpected error: " + e); +} +``` + + +## systemparameter.set + +set(key: string, value: string, callback: AsyncCallback<void>): void + +设置系统参数Key对应的值。 + +**系统能力:** SystemCapability.Startup.SystemInfo + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| key | string | 是 | 待设置的系统参数Key。 | +| value | string | 是 | 待设置的系统参数值。 | +| callback | AsyncCallback<void> | 是 | 回调函数。 | + +**示例:** + +```ts +try { + systemparameter.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); +} +``` + + +## systemparameter.set + +set(key: string, value: string): Promise<void> + +设置系统参数Key对应的值。 + +**系统能力:** SystemCapability.Startup.SystemInfo + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| key | string | 是 | 待设置的系统参数Key。 | +| value| string | 是 | 待设置的系统参数值。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| Promise<void> | Promise示例,用于异步获取结果。 | + +**示例:** + +```ts +try { + var p = systemparameter.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); +} +```