1 Star 0 Fork 5.1K

youguilin / docs

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

系统属性

导入模块

import parameter from '@ohos.systemparameter'

权限列表

方法

getSync(key: string, def?: string)

获取系统属性Key对应的值。

参数:

参数名

类型

必填

说明

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

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

获取系统属性Key对应的值。

参数:

参数名

类型

必填

说明

key

string

待查询的系统属性Key。

callback

AsyncCallback<string>

回调函数。

返回值:

示例:

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

获取系统属性Key对应的值。

参数:

参数名

类型

必填

说明

key

string

待查询的系统属性Key。

def

string

默认值。

callback

AsyncCallback<string>

回调函数。

返回值:

示例:

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)

获取系统属性Key对应的值。

参数:

参数名

类型

必填

说明

key

string

待查询的系统属性Key。

def

string

默认值。

返回值:

类型

说明

Promise<string>

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

setSync(key: string, value: string)

设置系统属性Key对应的值。

参数:

参数名

类型

必填

说明

key

string

待设置的系统属性Key。

value

string

待设置的系统属性值。

返回值:

示例:

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

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

设置系统属性Key对应的值。

参数:

参数名

类型

必填

说明

key

string

待查询的系统属性Key。

def

string

默认值。

callback

AsyncCallback<void>

回调函数。

返回值:

示例:

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)

设置系统属性Key对应的值。

参数:

参数名

类型

必填

说明

key

string

待查询的系统属性Key。

def

string

默认值。

返回值:

类型

说明

Promise<string>

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

搜索帮助