1# System Parameter 2 3> **NOTE**<br> 4> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. 5> - This is a system API and cannot be called by third-party applications. 6 7## Modules to Import 8 9```ts 10import parameter from '@ohos.systemParameter' 11``` 12 13 14## parameter.getSync 15 16getSync(key: string, def?: string): string 17 18Obtains the value of the attribute with the specified key. 19 20**System capability**: SystemCapability.Startup.SysInfo 21 22**Parameters** 23 24| Name| Type| Mandatory| Description| 25| -------- | -------- | -------- | -------- | 26| key | string | Yes| Key of the system attribute.| 27| def | string | No| Default value.| 28 29**Return value** 30 31| Type| Description| 32| -------- | -------- | 33| 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.| 34 35**Example** 36 37```ts 38try { 39 var info = parameter.getSync("test.parameter.key"); 40 console.log(JSON.stringify(info)); 41}catch(e){ 42 console.log("getSync unexpected error: " + e); 43} 44``` 45 46 47## parameter.get 48 49get(key: string, callback: AsyncCallback<string>): void 50 51Obtains the value of the attribute with the specified key. This API uses an asynchronous callback to return the result. 52 53**System capability**: SystemCapability.Startup.SysInfo 54 55**Parameters** 56 57| Name| Type| Mandatory| Description| 58| -------- | -------- | -------- | -------- | 59| key | string | Yes| Key of the system attribute.| 60| callback | AsyncCallback<string> | Yes| Callback used to return the result.| 61 62**Example** 63 64```ts 65try { 66 parameter.get("test.parameter.key", function (err, data) { 67 if (err == undefined) { 68 console.log("get test.parameter.key value success:" + data) 69 } else { 70 console.log(" get test.parameter.key value err:" + err.code) 71 }}); 72}catch(e){ 73 console.log("get unexpected error: " + e); 74} 75``` 76 77 78## parameter.get 79 80get(key: string, def: string, callback: AsyncCallback<string>): void 81 82Obtains the value of the attribute with the specified key. This API uses an asynchronous callback to return the result. 83 84**System capability**: SystemCapability.Startup.SysInfo 85 86**Parameters** 87 88| Name| Type| Mandatory| Description| 89| -------- | -------- | -------- | -------- | 90| key | string | Yes| Key of the system attribute.| 91| def | string | Yes| Default value.| 92| callback | AsyncCallback<string> | Yes| Callback used to return the result.| 93 94**Example** 95 96```ts 97try { 98 parameter.get("test.parameter.key", "default", function (err, data) { 99 if (err == undefined) { 100 console.log("get test.parameter.key value success:" + data) 101 } else { 102 console.log(" get test.parameter.key value err:" + err.code) 103 } 104 }); 105}catch(e){ 106 console.log("get unexpected error:" + e) 107} 108``` 109 110 111## parameter.get 112 113get(key: string, def?: string): Promise<string> 114 115Obtains the value of the attribute with the specified key. This API uses a promise to return the result. 116 117**System capability**: SystemCapability.Startup.SysInfo 118 119**Parameters** 120 121| Name| Type| Mandatory| Description| 122| -------- | -------- | -------- | -------- | 123| key | string | Yes| Key of the system attribute.| 124| def | string | No| Default value.| 125 126**Return value** 127 128| Type| Description| 129| -------- | -------- | 130| Promise<string> | Promise used to return the execution result.| 131 132**Example** 133 134```ts 135try { 136 var p = parameter.get("test.parameter.key"); 137 p.then(function (value) { 138 console.log("get test.parameter.key success: " + value); 139 }).catch(function (err) { 140 console.log("get test.parameter.key error: " + err.code); 141 }); 142}catch(e){ 143 console.log("get unexpected error: " + e); 144} 145``` 146 147 148## parameter.setSync 149 150setSync(key: string, value: string): void 151 152Sets a value for the attribute with the specified key. 153 154**System capability**: SystemCapability.Startup.SysInfo 155 156**Parameters** 157 158| Name| Type| Mandatory| Description| 159| -------- | -------- | -------- | -------- | 160| key | string | Yes| Key of the system attribute.| 161| value | string | Yes| System attribute value to set.| 162 163**Example** 164 165```ts 166try { 167 parameter.setSync("test.parameter.key", "default"); 168}catch(e){ 169 console.log("set unexpected error: " + e); 170} 171``` 172 173 174## parameter.set 175 176set(key: string, value: string, callback: AsyncCallback<void>): void 177 178Sets a value for the attribute with the specified key. This API uses an asynchronous callback to return the result. 179 180**System capability**: SystemCapability.Startup.SysInfo 181 182**Parameters** 183 184| Name| Type| Mandatory| Description| 185| -------- | -------- | -------- | -------- | 186| key | string | Yes| Key of the system attribute.| 187| value | string | Yes| System attribute value to set.| 188| callback | AsyncCallback<void> | Yes| Callback used to return the result.| 189 190**Example** 191 192```ts 193try { 194 parameter.set("test.parameter.key", "testValue", function (err, data) { 195 if (err == undefined) { 196 console.log("set test.parameter.key value success :" + data) 197 } else { 198 console.log("set test.parameter.key value err:" + err.code) 199 }}); 200}catch(e){ 201 console.log("set unexpected error: " + e); 202} 203``` 204 205 206## parameter.set 207 208set(key: string, value: string): Promise<void> 209 210Sets a value for the attribute with the specified key. This API uses a promise to return the result. 211 212**System capability**: SystemCapability.Startup.SysInfo 213 214**Parameters** 215 216| Name| Type| Mandatory| Description| 217| -------- | -------- | -------- | -------- | 218| key | string | Yes| Key of the system attribute.| 219| value| string | Yes | System attribute value to set.| 220 221**Return value** 222 223| Type| Description| 224| -------- | -------- | 225| Promise<void> | Promise used to return the execution result.| 226 227**Example** 228 229```ts 230try { 231 var p = para.set("test.parameter.key", "testValue"); 232 p.then(function (value) { 233 console.log("set test.parameter.key success: " + value); 234 }).catch(function (err) { 235 console.log(" set test.parameter.key error: " + err.code); 236 }); 237}catch(e){ 238 console.log("set unexpected error: " + e); 239} 240``` 241