# systemParameter
## Modules to Import
```
import parameter from '@ohos.systemParameter'
```
## Required Permissions
None
## parameter.getSync
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);
}
```
## parameter.get
get\(key: string, callback: AsyncCallback\)
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
|
**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);
}
```
## parameter.get
get\(key: string, def: string, callback: AsyncCallback\)
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
|
**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)
}
```
## parameter.get
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);
}
```
## parameter.setSync
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
|
**Example**
```
try {
parameter.setSync("test.parameter.key", "default");
}catch(e){
console.log("set unexpected error: " + e);
}
```
## parameter.set
set\(key: string, value: string, callback: AsyncCallback\)
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.
|
**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);
}
```
## parameter.set
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);
}
```