1 Star 0 Fork 5.1K

youguilin / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
system-attribute.md 35.50 KB
一键复制 编辑 原始数据 按行查看 历史
mamingshuai 提交于 2021-06-02 01:00 . update OpenHarmony 2.0 Canary

System Attribute

Modules to Import

import parameter from '@ohos.systemparameter'

Required Permissions

None

Functions

getSync(key: string, def?: string)

Gets the value of the attribute with the specified key.

Parameters

Name

Type

Mandatory

Description

key

string

Yes

Key of the system attribute

def

string

No

Default value

Return Values

Type

Description

string

System attribute value. If the specified key does not exist, the default value is returned. If no default value has been set, an empty string will be returned.

Example

try {
    var info = parameter.getSync("test.parameter.key");
    console.log(JSON.stringify(info));
}catch(e){
    console.log("getSync unexpected error: " + e);
}

get(key: string, callback: AsyncCallback<string>)

Gets the value of the attribute with the specified key.

Parameters

Name

Type

Mandatory

Description

key

string

Yes

Key of the system attribute

callback

AsyncCallback<string>

Yes

Callback function

Return Values

None.

Example

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);
}

get(key: string, def: string, callback: AsyncCallback<string>)

Gets the value of the attribute with the specified key.

Parameters

Name

Type

Mandatory

Description

key

string

Yes

Key of the system attribute

def

string

Yes

Default value

callback

AsyncCallback<string>

Yes

Callback function

Return Values

None.

Example

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)
}

get(key: string, def?: string)

Gets the value of the attribute with the specified key.

Parameters

Name

Type

Mandatory

Description

key

string

Yes

Key of the system attribute

def

string

No

Default value

Return Values

Type

Description

Promise<string>

Promise, which is used to obtain the result asynchronously

Example

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);
}

setSync(key: string, value: string)

Sets a value for the attribute with the specified key.

Parameters

Name

Type

Mandatory

Description

key

string

Yes

Key of the system attribute

value

string

Yes

System attribute value to set

Return Values

None.

Example

try {
    parameter.setSync("test.parameter.key", "default");
}catch(e){
    console.log("set unexpected error: " + e);
}

set(key: string, value: string, callback: AsyncCallback<void>)

Sets a value for the attribute with the specified key.

Parameters

Name

Type

Mandatory

Description

key

string

Yes

Key of the system attribute

def

string

Yes

Default value

callback

AsyncCallback<void>

Yes

Callback function.

Return Values

None.

Example

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);
}

set(key: string, def?: string)

Sets a value for the attribute with the specified key.

Parameters

Name

Type

Mandatory

Description

key

string

Yes

Key of the system attribute

def

string

No

Default value

Return Values

Type

Description

Promise<string>

Promise, which is used to obtain the result asynchronously

Example

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);
}
1
https://gitee.com/yougl/docs.git
git@gitee.com:yougl/docs.git
yougl
docs
docs
master

搜索帮助