# System Attribute - [Modules to Import](#en-us_topic_0000001094819718_section370mcpsimp) - [Required Permissions](#en-us_topic_0000001094819718_section373mcpsimp) - [Functions](#en-us_topic_0000001094819718_section1319529172015) - [getSync\(key: string, def?: string\)](#en-us_topic_0000001094819718_section3381192816421) - [get\(key: string, callback: AsyncCallback\)](#en-us_topic_0000001094819718_section19655131534912) - [get\(key: string, def: string, callback: AsyncCallback\)](#en-us_topic_0000001094819718_section045334733915) - [get\(key: string, def?: string\)](#en-us_topic_0000001094819718_section10288162818402) - [setSync\(key: string, value: string\)](#en-us_topic_0000001094819718_section63102185493) - [set\(key: string, value: string, callback: AsyncCallback\)](#en-us_topic_0000001094819718_section18770184911197) - [set\(key: string, def?: string\)](#en-us_topic_0000001094819718_section187724496193) ## 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\) 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\) 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\) 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); } ```