未验证 提交 d375afbc 编写于 作者: C cheng_jinsong 提交者: Gitee

update zh-cn/application-dev/reference/apis/js-apis-system-parameter.md.

Signed-off-by: Ncheng_jinsong <chengjinsong2@huawei.com>
Signed-off-by: Ncheng_jinsong <chengjinsong2@huawei.com>
上级 453b8e58
...@@ -3,20 +3,19 @@ ...@@ -3,20 +3,19 @@
系统参数(SystemParameter)是为各系统服务提供的简单易用的键值对访问接口,各个系统服务可以定义系统参数来描述该服务的状态信息,或者通过系统参数来改变系统服务的行为。其基本操作原语为get和set,通过get可以查询系统参数的值,通过set可以修改系统参数的值。 系统参数(SystemParameter)是为各系统服务提供的简单易用的键值对访问接口,各个系统服务可以定义系统参数来描述该服务的状态信息,或者通过系统参数来改变系统服务的行为。其基本操作原语为get和set,通过get可以查询系统参数的值,通过set可以修改系统参数的值。
详细的系统参数设计原理及定义可参考 详细的系统参数设计原理及定义可参考
[系统参数](../../../device-dev/subsystems/subsys-boot-init-sysparam.md) [系统参数](../../../device-dev/subsystems/subsys-boot-init-sysparam.md)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> - 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 由于系统参数都是各个系统服务的内部信息和控制参数,每个系统参数都有各自不同的DAC和MAC访问控制权限,三方应用不能使用此类接口。 > - 由于系统参数都是各个系统服务的内部信息和控制参数,每个系统参数都有各自不同的DAC和MAC访问控制权限,三方应用不能使用此类接口。
## 导入模块 ## 导入模块
```ts ```ts
import parameter from '@ohos.systemparameter' import systemparameter from '@ohos.systemparameter'
``` ```
## systemparameter.getSync
## parameter.getSync
getSync(key: string, def?: string): string getSync(key: string, def?: string): string
...@@ -41,15 +40,14 @@ getSync(key: string, def?: string): string ...@@ -41,15 +40,14 @@ getSync(key: string, def?: string): string
```ts ```ts
try { try {
var info = parameter.getSync("const.ohos.apiversion"); var info = systemparameter.getSync("const.ohos.apiversion");
console.log(JSON.stringify(info)); console.log(JSON.stringify(info));
}catch(e){ }catch(e){
console.log("getSync unexpected error: " + e); console.log("getSync unexpected error: " + e);
} }
``` ```
## systemparameter.get
## parameter.get
get(key: string, callback: AsyncCallback&lt;string&gt;): void get(key: string, callback: AsyncCallback&lt;string&gt;): void
...@@ -68,7 +66,7 @@ get(key: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -68,7 +66,7 @@ get(key: string, callback: AsyncCallback&lt;string&gt;): void
```ts ```ts
try { try {
parameter.get("const.ohos.apiversion", function (err, data) { systemparameter.get("const.ohos.apiversion", function (err, data) {
if (err == undefined) { if (err == undefined) {
console.log("get test.parameter.key value success:" + data) console.log("get test.parameter.key value success:" + data)
} else { } else {
...@@ -79,8 +77,7 @@ try { ...@@ -79,8 +77,7 @@ try {
} }
``` ```
## systemparameter.get
## parameter.get
get(key: string, def: string, callback: AsyncCallback&lt;string&gt;): void get(key: string, def: string, callback: AsyncCallback&lt;string&gt;): void
...@@ -100,7 +97,7 @@ get(key: string, def: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -100,7 +97,7 @@ get(key: string, def: string, callback: AsyncCallback&lt;string&gt;): void
```ts ```ts
try { try {
parameter.get("const.ohos.apiversion", "default", function (err, data) { systemparameter.get("const.ohos.apiversion", "default", function (err, data) {
if (err == undefined) { if (err == undefined) {
console.log("get test.parameter.key value success:" + data) console.log("get test.parameter.key value success:" + data)
} else { } else {
...@@ -112,8 +109,7 @@ try { ...@@ -112,8 +109,7 @@ try {
} }
``` ```
## systemparameter.get
## parameter.get
get(key: string, def?: string): Promise&lt;string&gt; get(key: string, def?: string): Promise&lt;string&gt;
...@@ -138,7 +134,7 @@ get(key: string, def?: string): Promise&lt;string&gt; ...@@ -138,7 +134,7 @@ get(key: string, def?: string): Promise&lt;string&gt;
```ts ```ts
try { try {
var p = parameter.get("const.ohos.apiversion"); var p = systemparameter.get("const.ohos.apiversion");
p.then(function (value) { p.then(function (value) {
console.log("get test.parameter.key success: " + value); console.log("get test.parameter.key success: " + value);
}).catch(function (err) { }).catch(function (err) {
...@@ -149,8 +145,7 @@ try { ...@@ -149,8 +145,7 @@ try {
} }
``` ```
## systemparameter.setSync
## parameter.setSync
setSync(key: string, value: string): void setSync(key: string, value: string): void
...@@ -165,26 +160,22 @@ setSync(key: string, value: string): void ...@@ -165,26 +160,22 @@ setSync(key: string, value: string): void
| key | string | 是 | 待设置的系统参数Key。 | | key | string | 是 | 待设置的系统参数Key。 |
| value | string | 是 | 待设置的系统参数值。 | | value | string | 是 | 待设置的系统参数值。 |
**说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> - 此接口只能用于系统应用的参数设置。
1、此接口只能用于系统应用的参数设置 > - 所授权的系统应用需要配置对应selinux和dac规则,具体配置方法请参照系统参数指导文档:[系统参数](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-boot-init-sysparam.md)。
2、所授权的系统应用需要配置对应selinux和dac规则,具体配置方法请参照系统参数指导文档:
https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-boot-init-sysparam.md
**示例:** **示例:**
```ts ```ts
try { try {
parameter.setSync("test.parameter.key", "default"); systemparameter.setSync("test.parameter.key", "default");
}catch(e){ }catch(e){
console.log("set unexpected error: " + e); console.log("set unexpected error: " + e);
} }
``` ```
## systemparameter.set
## parameter.set
set(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void set(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -200,19 +191,15 @@ set(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -200,19 +191,15 @@ set(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
| value | string | 是 | 待设置的系统参数值。 | | value | string | 是 | 待设置的系统参数值。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> - 此接口只能用于系统应用的参数设置。
1、此接口只能用于系统应用的参数设置 > - 所授权的系统应用需要配置对应selinux和dac规则,具体配置方法请参照系统参数指导文档:[系统参数](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-boot-init-sysparam.md)。
2、所授权的系统应用需要配置对应selinux和dac规则,具体配置方法请参照系统参数指导文档:
https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-boot-init-sysparam.md
**示例:** **示例:**
```ts ```ts
try { try {
parameter.set("test.parameter.key", "testValue", function (err, data) { systemparameter.set("test.parameter.key", "testValue", function (err, data) {
if (err == undefined) { if (err == undefined) {
console.log("set test.parameter.key value success :" + data) console.log("set test.parameter.key value success :" + data)
} else { } else {
...@@ -223,8 +210,7 @@ try { ...@@ -223,8 +210,7 @@ try {
} }
``` ```
## systemparameter.set
## parameter.set
set(key: string, value: string): Promise&lt;void&gt; set(key: string, value: string): Promise&lt;void&gt;
...@@ -245,19 +231,15 @@ set(key: string, value: string): Promise&lt;void&gt; ...@@ -245,19 +231,15 @@ set(key: string, value: string): Promise&lt;void&gt;
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise示例,用于异步获取结果。 | | Promise&lt;void&gt; | Promise示例,用于异步获取结果。 |
**说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> - 此接口只能用于系统应用的参数设置。
1、此接口只能用于系统应用的参数设置 > - 所授权的系统应用需要配置对应selinux和dac规则,具体配置方法请参照系统参数指导文档:[系统参数](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-boot-init-sysparam.md)
2、所授权的系统应用需要配置对应selinux和dac规则,具体配置方法请参照系统参数指导文档:
https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-boot-init-sysparam.md
**示例:** **示例:**
```ts ```ts
try { try {
var p = para.set("test.parameter.key", "testValue"); var p = systemparameter.set("test.parameter.key", "testValue");
p.then(function (value) { p.then(function (value) {
console.log("set test.parameter.key success: " + value); console.log("set test.parameter.key success: " + value);
}).catch(function (err) { }).catch(function (err) {
...@@ -266,4 +248,4 @@ try { ...@@ -266,4 +248,4 @@ try {
}catch(e){ }catch(e){
console.log("set unexpected error: " + e); console.log("set unexpected error: " + e);
} }
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册