系統(tǒng)屬性
說明:
開發(fā)前請熟悉鴻蒙開發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
導(dǎo)入模塊
import parameter from '@ohos.systemParameter'
parameter.getSync
getSync(key: string, def?: string): string
獲取系統(tǒng)屬性Key對應(yīng)的值。
系統(tǒng)能力: SystemCapability.Startup.SysInfo
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
key | string | 是 | 待查詢的系統(tǒng)屬性Key。 |
def | string | 否 | 默認(rèn)值。 |
返回值:
類型 | 說明 |
---|---|
string | 系統(tǒng)屬性值,若key不存在,返回默認(rèn)值。若未指定默認(rèn)值,返回空字符串。 |
示例:
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
獲取系統(tǒng)屬性Key對應(yīng)的值。
系統(tǒng)能力: SystemCapability.Startup.SysInfo
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
key | string | 是 | 待查詢的系統(tǒng)屬性Key。 |
callback | AsyncCallback | 是 | 回調(diào)函數(shù)。 |
示例:
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
獲取系統(tǒng)屬性Key對應(yīng)的值。
系統(tǒng)能力: SystemCapability.Startup.SysInfo
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
key | string | 是 | 待查詢的系統(tǒng)屬性Key。 |
def | string | 是 | 默認(rèn)值。 |
callback | AsyncCallback | 是 | 回調(diào)函數(shù)。 |
示例:
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
獲取系統(tǒng)屬性Key對應(yīng)的值。
系統(tǒng)能力: SystemCapability.Startup.SysInfo
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
key | string | 是 | 待查詢的系統(tǒng)屬性Key。 |
def | string | 否 | 默認(rèn)值。 |
返回值:
類型 | 說明 |
---|---|
Promise | Promise示例,用于異步獲取結(jié)果。 |
示例:
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
設(shè)置系統(tǒng)屬性Key對應(yīng)的值。
系統(tǒng)能力: SystemCapability.Startup.SysInfo
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
key | string | 是 | 待設(shè)置的系統(tǒng)屬性Key。 |
value | string | 是 | 待設(shè)置的系統(tǒng)屬性值。 |
示例:
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
設(shè)置系統(tǒng)屬性Key對應(yīng)的值。
系統(tǒng)能力: SystemCapability.Startup.SysInfo
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
key | string | 是 | 待設(shè)置的系統(tǒng)屬性Key。 |
value | string | 是 | 待設(shè)置的系統(tǒng)屬性值。 |
callback | AsyncCallback | 是 | 回調(diào)函數(shù)。 |
示例:
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
設(shè)置系統(tǒng)屬性Key對應(yīng)的值。
系統(tǒng)能力: SystemCapability.Startup.SysInfo
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
key | string | 是 | 待待設(shè)置的系統(tǒng)屬性Key。 |
value | string | 否 | 待設(shè)置的系統(tǒng)屬性值。 |
返回值:
類型 | 說明HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿 |
---|---|
Promise | Promise示例,用于異步獲取結(jié)果。 |
示例:
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);
}
審核編輯 黃宇
-
鴻蒙
+關(guān)注
關(guān)注
57文章
2467瀏覽量
43615
發(fā)布評論請先 登錄
相關(guān)推薦
為什么系統(tǒng)屬性中顯示的系統(tǒng)內(nèi)存會有不同?
紡織企業(yè)MES系統(tǒng)下的設(shè)備管理
設(shè)備管理系統(tǒng)軟件有哪些
整理公共基礎(chǔ)庫子系統(tǒng)和系統(tǒng)屬性組件
【觸覺智能 Purple Pi OH 開發(fā)板體驗】修改OpenHarmony 設(shè)備廠家名稱 、硬件版本號 等系統(tǒng)屬性詳細(xì)步驟
基于.Net框架的設(shè)備管理系統(tǒng)的設(shè)計與實現(xiàn)
面向預(yù)測性維護(hù)的制造工業(yè)設(shè)備管理系統(tǒng)

設(shè)備管理系統(tǒng)建設(shè)的目標(biāo)及意義
鴻蒙實戰(zhàn)開發(fā):【瀏覽器制作】

鴻蒙開發(fā)接口定制管理:【@ohos.enterpriseDeviceManager (企業(yè)設(shè)備管理)】

鴻蒙開發(fā)設(shè)備管理:ohos.multimodalInput.inputDevice 輸入設(shè)備

鴻蒙開發(fā)設(shè)備管理:ohos.usb USB管理

設(shè)備管理系統(tǒng):是什么、誰需要、推薦設(shè)備管理系統(tǒng)

設(shè)備管理系統(tǒng),終結(jié)設(shè)備管理難題

評論