System Attribute
- Modules to Import
- Required Permissions
- Functions
- getSync(key: string, def?: string)
- get(key: string, callback: AsyncCallback<string>)
- get(key: string, def: string, callback: AsyncCallback<string>)
- get(key: string, def?: string)
- setSync(key: string, value: string)
- set(key: string, value: string, callback: AsyncCallback<void>)
- set(key: string, def?: string)
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
Return Values
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
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
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
Return Values
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
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
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
Return Values
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);
}