1# @ohos.settings (Data Item Settings) 2 3The **settings** module provides APIs for setting data items. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - If no value is obtained for the accessed data item, it indicates that the current system app does not add the value of the data item to the database. 10 11## Modules to Import 12 13```js 14import settings from '@ohos.settings'; 15``` 16## domainName 17 18Provides the domain name. 19 20### Attributes 21 22**System capability**: SystemCapability.Applications.Settings.Core 23 24| Name | Type | Readable| Writable| Description | 25|-----------------------------| ------ | ---- | ---- | ------------------------------------------------------------ | 26| DEVICE_SHARED<sup>11+</sup> | string | Yes | Yes | Shared device domain. | 27| USER_PROPERTY<sup>11+</sup> | string | Yes | Yes | User property domain. | 28 29## date 30 31Provides data items for setting the time and date formats. (Not supported yet.) 32 33### Attributes 34 35**System capability**: SystemCapability.Applications.Settings.Core 36 37| Name | Type | Readable| Writable| Description | 38| ------------------- | ------ | ---- | ---- | ------------------------------------------------------------ | 39| DATE_FORMAT | string | Yes | Yes | Date format.<br>The value can be **mm/dd/yyyy**, **dd/mm/yyyy**, or **yyyy/mm/dd**, where **mm** indicates the month, **dd** indicates the day, and **yyyy** indicates the year.| 40| TIME_FORMAT | string | Yes | Yes | Time format. The options are as follows:<br>- **12**: 12-hour format.<br>- **24**: 24-hour format.| 41| AUTO_GAIN_TIME | string | Yes | Yes | Whether the date, time, and time zone are automatically obtained from the Network Identity and Time Zone (NITZ).<br>The value **true** means that the date, time, and time zone are automatically obtained from NITZ;<br>**false** means the opposite.| 42| AUTO_GAIN_TIME_ZONE | string | Yes | Yes | Whether the time zone is automatically obtained from NITZ.<br>The value **true** means that the time zone is automatically obtained from NITZ;<br>**false** means the opposite.| 43 44## display 45 46Provides data items for setting the display effects. (Not supported yet.) 47 48### Attributes 49 50**System capability**: SystemCapability.Applications.Settings.Core 51 52| Name | Type | Readable| Writable| Description | 53| ----------------------------- | ------ | ---- | ---- |-------------------------------------------------------------------------------------------------------------| 54| FONT_SCALE | string | Yes | Yes | Scale factor of the font. The value is a floating point number. (In the current version, only fixed values can be queried.) | 55| SCREEN_BRIGHTNESS_STATUS | string | Yes | Yes | Screen brightness, with the value ranging from 0 to 255. | 56| AUTO_SCREEN_BRIGHTNESS | string | Yes | Yes | Whether automatic screen brightness adjustment is enabled.<br>- **AUTO_SCREEN_BRIGHTNESS_MODE**: Automatic screen brightness adjustment is enabled.<br>- **MANUAL_SCREEN_BRIGHTNESS_MODE**: Automatic screen brightness adjustment is disabled. | 57| AUTO_SCREEN_BRIGHTNESS_MODE | number | Yes | Yes | Value of **AUTO_SCREEN_BRIGHTNESS** when automatic screen brightness adjustment is enabled. | 58| MANUAL_SCREEN_BRIGHTNESS_MODE | number | Yes | Yes | Value of **AUTO_SCREEN_BRIGHTNESS** when automatic screen brightness adjustment is disabled. | 59| SCREEN_OFF_TIMEOUT | string | Yes | Yes | Waiting time for the device to enter the sleep state when not in use (unit: ms). | 60| DEFAULT_SCREEN_ROTATION | string | Yes | Yes | This attribute is invalid when screen auto-rotation is enabled; otherwise, the following options are available:<br>- **0**: The screen rotates by 0 degrees.<br>- **1**: The screen rotates by 90 degrees.<br>- **2**: The screen rotates by 180 degrees.<br>- **3**: The screen rotates by 270 degrees.| 61| ANIMATOR_DURATION_SCALE | string | Yes | Yes | Scale factor for the animation duration, which affects the start delay and duration of all such animations.<br>If the value is **0**, the animation ends immediately. The default value is **1**. | 62| TRANSITION_ANIMATION_SCALE | string | Yes | Yes | Scale factor for transition animations.<br>The value **0** indicates that the transition animations are disabled. | 63| WINDOW_ANIMATION_SCALE | string | Yes | Yes | Scale factor for normal window animations.<br>The value **0** indicates that window animations are disabled. | 64| DISPLAY_INVERSION_STATUS | string | Yes | Yes | Whether display color inversion is enabled.<br>- **1**: Display color inversion is enabled.<br>- **0**: Display color inversion is disabled. | 65 66## general 67 68Provides data items for setting the general information about the device. (Not supported yet.) 69 70### Attributes 71 72**System capability**: SystemCapability.Applications.Settings.Core 73 74| Name | Type | Readable| Writable| Description | 75| -------------------------------- | ------ | ---- | ---- | ------------------------------------------------------------ | 76| SETUP_WIZARD_FINISHED | string | Yes | Yes | Whether the startup wizard is running.<br>- If the value is **0**, the startup wizard is not running.<br>- If the value is not **0**, the startup wizard is running.| 77| END_BUTTON_ACTION | string | Yes | Yes | Action after the call end button is pressed if the user is not in a call.<br>- **0**: Nothing happens.<br>- **1**: The home screen is displayed.<br>- **2**: The device enters sleep mode and the screen is locked.<br>- **3**: The home screen is displayed. If the focus is already on the home screen, the device will enter sleep mode.| 78| ACCELEROMETER_ROTATION_STATUS | string | Yes | Yes | Whether the accelerometer is used to change screen orientation, that is, whether to enable auto-rotation.<br>- **1**: The accelerometer is used.<br>- **0**: The accelerometer is not used.| 79| DEVICE_PROVISION_STATUS | string | Yes | Yes | Whether the device is preconfigured.<br>On a multi-user device with a single system user, the screen may be locked when the value is **true**. In addition, other features cannot be started on the system user unless they are marked to display on the lock screen.| 80| HDC_STATUS | string | Yes | Yes | Whether the hard disk controller (HDC) on the USB device is enabled.<br>- **true**: HDC is enabled.<br>- **false**: HDC is disabled.| 81| BOOT_COUNTING | string | Yes | Yes | Number of boot operations after the device is powered on. | 82| CONTACT_METADATA_SYNC_STATUS | string | Yes | Yes | Whether contacts metadata synchronization is enabled.<br>- **true**: Contacts metadata synchronization is enabled.<br>- **false**: Contacts metadata synchronization is disabled.| 83| DEVICE_NAME | string | Yes | Yes | Device name. | 84| USB_STORAGE_STATUS | string | Yes | Yes | Whether USB mass storage is enabled.<br>- **true**: USB mass storage is enabled.<br>- **false**: USB mass storage is disabled.| 85| DEBUGGER_WAITING | string | Yes | Yes | Whether the device waits for the debugger when starting an application to debug.<br>- **1**: The device waits for the debugger.<br>- **0**: The device does not wait for the debugger. In this case, the application runs normally.| 86| DEBUG_APP_PACKAGE | string | Yes | Yes | Bundle name of the application to be debugged. | 87| ACCESSIBILITY_STATUS | string | Yes | Yes | Whether accessibility is enabled.<br>- **1**: Accessibility is enabled.<br>- **0**: Accessibility is disabled.| 88| ACTIVATED_ACCESSIBILITY_SERVICES | string | Yes | Yes | List of activated accessibility features. | 89| GEOLOCATION_ORIGINS_ALLOWED | string | Yes | Yes | Default geographic location that can be used by the browser. Multiple geographic locations are separated by spaces. | 90| SKIP_USE_HINTS | string | Yes | Yes | Whether the application should attempt to skip all introductory hints at the first startup. This feature is intended for temporary or experienced users.<br>- **1**: The application attempts to skip all introductory hints at the first startup.<br>- **0**: The application does not skip all introductory hints at the first startup.| 91| TOUCH_EXPLORATION_STATUS | string | Yes | Yes | Whether touch exploration is enabled.<br>- **1**: Touch exploration is enabled.<br>- **0**: Touch exploration is disabled.| 92 93## input 94 95Provides data items for setting input methods. (Not supported yet.) 96 97### Attributes 98 99**System capability**: SystemCapability.Applications.Settings.Core 100 101| Name | Type | Readable| Writable| Description | 102| ------------------------------------ | ------ | ---- | ---- | ------------------------------------------------------------ | 103| DEFAULT_INPUT_METHOD | string | Yes | Yes | Default input method and its ID. | 104| ACTIVATED_INPUT_METHOD_SUB_MODE | string | Yes | Yes | Type and ID of the default input method keyboard. | 105| ACTIVATED_INPUT_METHODS | string | Yes | Yes | List of activated input methods.<br>The list is a string that contains the IDs and keyboard types of activated input methods.<br>The IDs are separated by colons (:), and keyboard types are separated by semicolons (;).<br>An example format is **ima0:keyboardType0;keyboardType1;ima1:ima2:keyboardTypes0,** where **ima** indicates the ID of an input method, and **keyboardType** indicates the keyboard type.| 106| SELECTOR_VISIBILITY_FOR_INPUT_METHOD | string | Yes | Yes | Whether the input method selector is visible.<br>- **1**: The input method selector is visible.<br>- **0**: The input method selector is invisible.| 107| AUTO_CAPS_TEXT_INPUT | string | Yes | Yes | Whether automatic capitalization is enabled for the text editor.<br>- **0**: Automatic capitalization is disabled.<br>- **1**: Automatic capitalization is enabled.| 108| AUTO_PUNCTUATE_TEXT_INPUT | string | Yes | Yes | Whether automatic punctuation is enabled for the text editor. Automatic punctuation enables the text editor to convert two spaces into a period (.) and a space.<br>- **0**: Automatic punctuation is disabled.<br>- **1**: Automatic punctuation is enabled.| 109| AUTO_REPLACE_TEXT_INPUT | string | Yes | Yes | Whether autocorrect is enabled for the text editor. Autocorrect enables the text editor to correct typos.<br>- **0**: Autocorrect is disabled.<br>- **1**: Autocorrect is enabled | 110| SHOW_PASSWORD_TEXT_INPUT | string | Yes | Yes | Whether password presentation is enabled in the text editor. Password presentation enables the text editor to show password characters when the user types them.<br>- **0**: Password presentation is disabled.<br>- **1**: Password presentation is enabled.| 111 112## network 113 114Provides data items for setting network information. (Not supported yet.) 115 116### Attributes 117 118**System capability**: SystemCapability.Applications.Settings.Core 119 120| Name | Type | Readable| Writable| Description | 121| ------------------------ | ------ | ---- | ---- | ------------------------------------------------------------ | 122| DATA_ROAMING_STATUS | string | Yes | Yes | Whether data roaming is enabled.<br>**true**: Data roaming is enabled.<br>**false**: Data roaming is disabled.| 123| HTTP_PROXY_CFG | string | Yes | Yes | Host name and port number of the global HTTP proxy. The host name and port number are separated by a colon (:).| 124| NETWORK_PREFERENCE_USAGE | string | Yes | Yes | User preferences for the network to use. | 125 126## phone 127 128Provides data items for setting the modes of answering incoming and outgoing calls. (Not supported yet.) 129 130### Attributes 131 132**System capability**: SystemCapability.Applications.Settings.Core 133 134| Name | Type | Readable| Writable| Description | 135| ------------------ | ------ | ---- | ---- | ------------------------------------------------------------ | 136| RTT_CALLING_STATUS | string | Yes | Yes | Whether the real-time text (RTT) feature is enabled. If this feature is enabled, incoming and outgoing calls are answered as RTT calls when supported by the device and carrier.<br> **1**: RTT is enabled.<br> **0**: RTT is disabled.| 137 138## sound 139 140Provides data items for setting the sound effects. (Not supported yet.) 141 142### Attributes 143 144**System capability**: SystemCapability.Applications.Settings.Core 145 146| Name | Type | Readable| Writable| Description | 147| ---------------------------- | ------ | ---- | ---- | ------------------------------------------------------------ | 148| VIBRATE_WHILE_RINGING | string | Yes | Yes | Whether the device vibrates when it is ringing for an incoming call. This attribute is applicable to the phone and settings applications<br>and affects only the scenario where the device rings for an incoming call. It does not affect any other application or scenario.| 149| DEFAULT_ALARM_ALERT | string | Yes | Yes | Storage area of the system default alarms and alerts. | 150| DTMF_TONE_TYPE_WHILE_DIALING | string | Yes | Yes | Type of the dual tone multi-frequency (DTMF) tone played while dialing.<br>**0**: normal short tone.<br>**1**: long tone.| 151| DTMF_TONE_WHILE_DIALING | string | Yes | Yes | Whether the DTMF tone is played when dialing.<br>**1**: DTMF tone is played when dialing.<br>**0**: DTMF tone is not played when dialing.| 152| AFFECTED_MODE_RINGER_STREAMS | string | Yes | Yes | Effect on audio streams determined by changes in the ringing mode and Do Not Disturb (DND) mode. If you want a specific audio stream to be affected by changes of the ringing mode and DDN mode, set the corresponding bit to **1**.| 153| AFFECTED_MUTE_STREAMS | string | Yes | Yes | Audio streams affected by the mute mode. If you want a specific audio stream to remain muted in mute mode, set the corresponding bit to **1**.| 154| DEFAULT_NOTIFICATION_SOUND | string | Yes | Yes | Storage area of the system default notification tone. | 155| DEFAULT_RINGTONE | string | Yes | Yes | Storage area of the system default ringtone. | 156| SOUND_EFFECTS_STATUS | string | Yes | Yes | Whether the sound feature is available.<br>**0**: The feature is not available.<br>**1**: The feature is available. | 157| VIBRATE_STATUS | string | Yes | Yes | Whether the device vibrates for an event. This attribute is used inside the system.<br>**1**: The device vibrates for an event.<br>**0**: The device does not vibrate for an event.| 158| HAPTIC_FEEDBACK_STATUS | string | Yes | Yes | Whether haptic feedback is enabled.<br>**true**: Haptic feedback is enabled.<br>**false**: Haptic feedback is disabled.| 159 160## TTS 161 162Provides data items for setting text-to-speech (TTS) information. (Not supported yet.) 163 164### Attributes 165 166**System capability**: SystemCapability.Applications.Settings.Core 167 168| Name | Type | Readable| Writable| Description | 169| ------------------- | ------ | ---- | ---- | ------------------------------------------------------------ | 170| DEFAULT_TTS_PITCH | string | Yes | Yes | Default pitch of the TTS engine.<br>100 = 1x. If the value is set to **200**, the frequency is twice the normal sound frequency.| 171| DEFAULT_TTS_RATE | string | Yes | Yes | Default voice rate of the TTS engine.<br>100 = 1x. | 172| DEFAULT_TTS_SYNTH | string | Yes | Yes | Default TTS engine. | 173| ENABLED_TTS_PLUGINS | string | Yes | Yes | List of activated plug-in packages used for TTS. Multiple plug-in packages are separated by spaces. | 174 175 176## wireless 177 178Provides data items for setting wireless network information. (Not supported yet.) 179 180### Attributes 181 182**System capability**: SystemCapability.Applications.Settings.Core 183 184| Name | Type | Readable| Writable| Description | 185| --------------------------------- | ------ | ---- | ---- | ------------------------------------------------------------ | 186| BLUETOOTH_DISCOVER_ABILITY_STATUS | string | Yes | Yes | Whether the device can be discovered or connected by other devices through Bluetooth.<br>**0**: The device cannot be discovered or connected.<br>**1**: The device can be connected but cannot be discovered.<br>**2**: The device can be discovered and connected.| 187| BLUETOOTH_DISCOVER_TIMEOUT | string | Yes | Yes | Duration for discovering a device through Bluetooth, in seconds.<br>After the duration expires, the device cannot be discovered through Bluetooth.| 188| AIRPLANE_MODE_RADIOS | string | Yes | Yes | List of radio signals to be disabled when airplane mode is enabled.<br>Multiple radio signals are separated by commas (,).<br>The list can include the following: **BLUETOOTH_RADIO**, **CELL_RADIO**, **NFC_RADIO**, and **WIFI_RADIO**.| 189| BLUETOOTH_RADIO | string | Yes | No | A value of **AIRPLANE_MODE_RADIOS** to indicate that Bluetooth is disabled in airplane mode.| 190| CELL_RADIO | string | Yes | No | A value of **AIRPLANE_MODE_RADIOS** to indicate that cellular radio is disabled in airplane mode.| 191| NFC_RADIO | string | Yes | No | A value of **AIRPLANE_MODE_RADIOS** to indicate that NFC is disabled in airplane mode.| 192| WIFI_RADIO | string | Yes | No | A value of **AIRPLANE_MODE_RADIOS** to indicate that Wi-Fi is disabled in airplane mode.| 193| BLUETOOTH_STATUS | string | Yes | Yes | Whether Bluetooth is available.<br>- **true**: Bluetooth is available.<br>- **false**: Bluetooth is unavailable.| 194| OWNER_LOCKDOWN_WIFI_CFG | string | Yes | Yes | Whether the Wi-Fi configuration created by the application of the device owner should be locked down.<br>- **true**: The Wi-Fi configuration should be locked down.<br>- **false**: The Wi-Fi configuration should not be locked down.| 195| WIFI_DHCP_MAX_RETRY_COUNT | string | Yes | Yes | Maximum number of attempts to obtain an IP address from the DHCP server. | 196| WIFI_TO_MOBILE_DATA_AWAKE_TIMEOUT | string | Yes | Yes | Maximum duration to hold a wake lock when waiting for the mobile data connection after the Wi-Fi connection is disconnected. | 197| WIFI_STATUS | string | Yes | Yes | Whether Wi-Fi is available.<br>- **true**: Wi-Fi is available.<br>- **false**: Wi-Fi is unavailable.| 198| WIFI_WATCHDOG_STATUS | string | Yes | Yes | Whether Wi-Fi watchdog is available.<br>- **true**: Wi-Fi watchdog is available.<br>- **false**: Wi-Fi watchdog is unavailable.| 199 200 201## settings.setValue<sup>10+</sup> 202 203setValue(context: Context, name: string, value: string, callback: AsyncCallback\<boolean>): void 204 205Sets the value for a data item. This API uses an asynchronous callback to return the result. 206 207**Model restriction**: This API can be used only in the stage model. 208 209**System capability**: SystemCapability.Applications.Settings.Core 210 211**Required permissions**: ohos.permission.MANAGE_SETTINGS (available only to system applications) 212 213**Parameters** 214 215| Name | Type | Mandatory| Description | 216| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 217| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 218| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 219| value | string | Yes | Value of the data item. The value range varies by service. | 220| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. Returns **true** if the operation is successful; returns **false** otherwise. | 221 222**Example** 223 224```js 225import settings from '@ohos.settings'; 226 227// Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValue API will update its value.) 228const context: Context = getContext(this); 229settings.setValue(context, settings.display.SCREEN_BRIGHTNESS_STATUS, '100', (status) => { 230 console.log('Callback return whether value is set.'); 231}); 232``` 233 234## settings.setValue<sup>10+</sup> 235 236setValue(context: Context, name: string, value: string): Promise\<boolean> 237 238Sets the value for a data item. This API uses a promise to return the result. 239 240**Model restriction**: This API can be used only in the stage model. 241 242**System capability**: SystemCapability.Applications.Settings.Core 243 244**Required permissions**: ohos.permission.MANAGE_SETTINGS (available only to system applications) 245 246**Parameters** 247 248| Name | Type | Mandatory| Description | 249| ------- | ------- | ---- | ------------------------------------------------------------ | 250| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 251| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 252| value | string | Yes | Value of the data item. The value range varies by service. | 253 254**Return value** 255 256| Type | Description | 257| ----------------- | -------------------------------------------------- | 258| Promise\<boolean> | Promise used to return the result. Returns **true** if the operation is successful; returns **false** otherwise.| 259 260**Example** 261 262```js 263import settings from '@ohos.settings'; 264 265// Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValue API will update its value.) 266const context: Context = getContext(this); 267settings.setValue(context, settings.display.SCREEN_BRIGHTNESS_STATUS, '100').then((status) => { 268 console.log('Callback return whether value is set.'); 269}); 270``` 271 272## settings.setValue<sup>11+</sup> 273 274setValue(context: Context, name: string, value: string, domainName: string): Promise\<boolean> 275 276Sets the value for a data item. This API uses a promise to return the result. 277 278**Model restriction**: This API can be used only in the stage model. 279 280**System capability**: SystemCapability.Applications.Settings.Core 281 282**Required permissions**: 283- ohos.permission.MANAGE_SETTINGS for writing the DEVICE_SHARED and USER_PROPERTY fields (available only to system applications); 284- ohos.permission.MANAGE_SECURE_SETTINGS for writing the USER_SECURITY field (available only to system applications) 285 286**Parameters** 287 288| Name | Type | Mandatory| Description | 289| -------- | ---------------------- | ---- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 290| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md). | 291| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items | 292| value | string | Yes | Value of the data item. The value range varies by service. | 293|domainName| string | Yes | Domain name to set.<br>- **domainName.DEVICE_SHARED**:<br> shared device domain<br>- **domainName.USER_PROPERTY**:<br> user property domain<br>- **domainName.USER_SECURITY**:<br> user security domain (for system applications only)| 294 295**Return value** 296 297| Type | Description | 298| ---------------- | ----------------------------------- | 299| Promise\<string> | Promise used to return the result. Returns **true** if the operation is successful; returns **false** otherwise.| 300 301**Error codes** 302 303For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 304 305| ID| Error Message| 306| ------- | -------- | 307| 201 | Permission denied. | 308 309**Example** 310 311```js 312import settings from '@ohos.settings'; 313 314// Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValue API will update its value.) 315const context: Context = getContext(this); 316settings.setValue(context, settings.display.SCREEN_BRIGHTNESS_STATUS, '100', settings.domainName.DEVICE_SHARED).then((status) => { 317 console.log(`callback:return whether value is set.`) 318}); 319``` 320 321## settings.getValue<sup>10+</sup> 322 323getValue(context: Context, name: string, callback: AsyncCallback\<string>): void 324 325Obtains the value of a data item in the database. This API uses an asynchronous callback to return the result. 326 327**Model restriction**: This API can be used only in the stage model. 328 329**System capability**: SystemCapability.Applications.Settings.Core 330 331**Parameters** 332 333| Name | Type | Mandatory| Description | 334| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 335| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 336| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 337| callback | AsyncCallback\<string> | Yes | Callback used to return the value of the data item. | 338 339**Example** 340 341```js 342import settings from '@ohos.settings'; 343const context: Context = getContext(this); 344settings.getValue(context, settings.display.SCREEN_BRIGHTNESS_STATUS, (err, value) => { 345 if (err) { 346 console.error(`Failed to get the setting. ${err.message} `); 347 return; 348 } 349 console.log(`callback:value -> ${value}`) 350}); 351``` 352 353## settings.getValue<sup>10+</sup> 354 355getValue(context: Context, name: string): Promise\<string> 356 357Obtains the value of a data item in the database. This API uses a promise to return the result. 358 359**Model restriction**: This API can be used only in the stage model. 360 361**System capability**: SystemCapability.Applications.Settings.Core 362 363**Parameters** 364 365| Name | Type | Mandatory| Description | 366| ------- | ------- | ---- | ------------------------------------------------------------ | 367| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 368| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 369 370**Return value** 371 372| Type | Description | 373| ---------------- | ----------------------------------- | 374| Promise\<string> | Promise used to return the result. return the value of the data item.| 375 376**Example** 377 378```js 379import settings from '@ohos.settings'; 380const context: Context = getContext(this); 381settings.getValue(context, settings.display.SCREEN_BRIGHTNESS_STATUS).then((value) => { 382 console.log(`promise:value -> ${value}`) 383}); 384``` 385 386## settings.getValue<sup>11+</sup> 387 388getValue(context: Context, name: string, domainName: string): Promise\<string>; 389 390Obtains the value of a data item in the database. This API uses a promise to return the result. 391 392**Model restriction**: This API can be used only in the stage model. 393 394**System capability**: SystemCapability.Applications.Settings.Core 395 396**Required permissions**: 397- ohos.permission.MANAGE_SECURE_SETTINGS for reading the USER_SECURITY field (available only to system applications) 398 399**Parameters** 400 401| Name | Type | Mandatory| Description | 402| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 403| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 404| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 405|domainName| string | Yes | Domain name to set.<br>- **domainName.DEVICE_SHARED**:<br> shared device domain<br>- **domainName.USER_PROPERTY**:<br> user property domain<br>- **domainName.USER_SECURITY**:<br> user security domain (for system applications only)| 406 407**Return value** 408 409| Type | Description | 410| ---------------- | ----------------------------------- | 411| Promise\<string> | Promise used to return the result. return the value of the data item.| 412 413**Example** 414 415```js 416import settings from '@ohos.settings'; 417 418// Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the getValue API will update its value.) 419const context: Context = getContext(this); 420settings.getValue(context, settings.display.SCREEN_BRIGHTNESS_STATUS, settings.domainName.DEVICE_SHARED).then((value) => { 421 console.log(`Promise:value -> ${value}`); 422}); 423``` 424 425## settings.getValueSync<sup>10+</sup> 426 427getValueSync(context: Context, name: string, defValue: string): string; 428 429Obtains the value of a data item. Unlike **getValue**, this API returns the result synchronously. 430 431**Model restriction**: This API can be used only in the stage model. 432 433**System capability**: SystemCapability.Applications.Settings.Core 434 435**Parameters** 436 437| Name | Type | Mandatory| Description | 438| -------- | ------- | ---- | ------------------------------------------------------------ | 439| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 440| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 441| defValue | string | Yes | Default value, which is returned when the value of a data item is not found in the database. Set this parameter as needed.| 442 443**Return value** 444 445| Type | Description | 446| ------ | ---------------- | 447| string | Value of the data item.| 448 449**Example** 450 451```js 452import settings from '@ohos.settings'; 453 454// Obtain the value of SCREEN_BRIGHTNESS_STATUS (this data item already exists in the database). 455const context: Context = getContext(this); 456let value = settings.getValueSync(context, settings.display.SCREEN_BRIGHTNESS_STATUS, '10'); 457``` 458 459## settings.getValueSync<sup>11+</sup> 460 461getValueSync(context: Context, name: string, defValue: string, domainName: string): string; 462 463Obtains the value of a data item. Unlike **getValue**, this API returns the result synchronously. 464 465**Model restriction**: This API can be used only in the stage model. 466 467**System capability**: SystemCapability.Applications.Settings.Core 468 469**Required permissions**: 470- ohos.permission.MANAGE_SECURE_SETTINGS for reading the USER_SECURITY field (available only to system applications) 471 472**Parameters** 473 474| Name | Type | Mandatory| Description | 475|------------| ---------------------- | ---- | ------------------------------------------------------------ | 476| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 477| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 478| defValue | string | Yes | Value of the data item. The value range varies by service. | 479| domainName | string | Yes | Domain name to set.<br>- **domainName.DEVICE_SHARED**:<br> shared device domain<br>- **domainName.USER_PROPERTY**:<br> user property domain<br>- **domainName.USER_SECURITY**:<br> user security domain (for system applications only)| 480 481 482**Return value** 483 484| Type | Description | 485| ---------------- | ----------------------------------- | 486| string | Value of the data item. | 487 488**Example** 489 490```js 491import settings from '@ohos.settings'; 492 493// Update the value of .SCREEN_BRIGHTNESS_STATUS (this data item already exists in the database). 494const context: Context = getContext(this); 495let value = settings.getValueSync(context, settings.display.SCREEN_BRIGHTNESS_STATUS, '100', settings.domainName.DEVICE_SHARED); 496``` 497 498## settings.setValueSync<sup>10+</sup> 499 500setValueSync(context: Context, name: string, value: string): boolean 501 502Sets the value for a data item. Unlike **setValue**, this API returns the result synchronously. 503 504- If the specified data item exists in the database, the **setValueSync** method updates the value of the data item. 505- If the data item does not exist in the database, the **setValueSync** method inserts the data item into the database. 506 507**Model restriction**: This API can be used only in the stage model. 508 509**System capability**: SystemCapability.Applications.Settings.Core 510 511**Required permissions**: ohos.permission.MANAGE_SETTINGS (available only to system applications) 512 513**Parameters** 514 515| Name | Type | Mandatory| Description | 516| ------- | ------- | ---- | ------------------------------------------------------------ | 517| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 518| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 519| value | string | Yes | Value of the data item. The value range varies by service. | 520 521**Return value** 522 523| Type | Description | 524| ------- | ------------------------------------------------------------ | 525| boolean | Result indicating whether the value is set successfully. Returns **true** if the value is set successfully; returns **false** otherwise.| 526 527**Example** 528 529```js 530import settings from '@ohos.settings'; 531 532// Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValueSync API will update its value.) 533const context: Context = getContext(this); 534let ret = settings.setValueSync(context, settings.display.SCREEN_BRIGHTNESS_STATUS, '100'); 535``` 536 537## settings.setValueSync<sup>11+</sup> 538 539setValueSync(context: Context, name: string, value: string, domainName: string): boolean 540 541Sets the value for a data item. Unlike **setValue**, this API returns the result synchronously. 542 543- If the specified data item exists in the database, the **setValueSync** method updates the value of the data item. 544- If the data item does not exist in the database, the **setValueSync** method inserts the data item into the database. 545 546**Model restriction**: This API can be used only in the stage model. 547 548**System capability**: SystemCapability.Applications.Settings.Core 549 550**Required permissions**: 551- ohos.permission.MANAGE_SETTINGS for writing the DEVICE_SHARED and USER_PROPERTY fields (available only to system applications); 552- ohos.permission.MANAGE_SECURE_SETTINGS for writing the USER_SECURITY field (available only to system applications) 553 554**Parameters** 555 556| Name | Type | Mandatory| Description | 557|---------| ---------------------- | ---- | ------------------------------------------------------------ | 558| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 559| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 560| value | string | Yes | Value of the data item. The value range varies by service. | 561| domainName | string | Yes | Domain name to set.<br>- **domainName.DEVICE_SHARED**:<br> shared device domain<br>- **domainName is domainName.USER_PROPERTY**:<br> user property domain<br>- **domainName.USER_SECURITY**:<br> user security domain (for system applications only)| 562 563**Return value** 564 565| Type | Description | 566| ---------------- | ----------------------------------- | 567| boolean | Result indicating whether the value is set successfully. Returns **true** if the value is set successfully; returns **false** otherwise.| 568 569**Error codes** 570 571For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 572 573| ID| Error Message| 574| ------- | -------- | 575| 201 | Permission denied. | 576 577**Example** 578 579```js 580import settings from '@ohos.settings'; 581 582// Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValueSync API will update its value.) 583const context: Context = getContext(this); 584let ret = settings.setValueSync(context, settings.display.SCREEN_BRIGHTNESS_STATUS, '100', settings.domainName.DEVICE_SHARED); 585``` 586 587## settings.registerKeyObserver<sup>11+</sup> 588 589registerKeyObserver(context: Context, name: string, domainName: string, observer:AsyncCallback\<void>): boolean 590 591Registers an observer in the specified context so that the specified data item can be observed in the specified domain name. When the data item value changes, the registered callback is called. Returns **true** if the registration is successful; returns **false** otherwise. 592 593**Model restriction**: This API can be used only in the stage model. 594 595**System capability**: SystemCapability.Applications.Settings.Core 596 597**Parameters** 598 599| Name | Type | Mandatory| Description | 600| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 601| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 602| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 603|domainName| string | Yes | Domain name to set.<br>- **domainName.DEVICE_SHARED**:<br> shared device domain<br>- **domainName is domainName.USER_PROPERTY**:<br> user property domain<br>- **domainName.USER_SECURITY**:<br> user security domain (for system applications only)| 604|observer | AsyncCallback\<void> | Yes | Callback used to return the value of the data item. | 605 606**Return value** 607 608| Type | Description | 609| ---------------- | ----------------------------------- | 610| boolean | Result indicating whether the value is set successfully. Returns **true** if the value is set successfully; returns **false** otherwise.| 611 612**Example** 613 614```js 615import settings from '@ohos.settings'; 616 617const context: Context = getContext(this); 618settings.registerKeyObserver(context, settings.display.SCREEN_BRIGHTNESS_STATUS, settings.domainName.DEVICE_SHARED, (err, val) => { 619 if (err) { 620 console.error(`Failed to get the setting. ${err.message} `); 621 return; 622 } 623 console.log(`callback:value -> ${JSON.stringify(val)}`) 624 let value:string = settings.getValueSync(context, settings.display.SCREEN_BRIGHTNESS_STATUS, '10'); 625 console.log(`Promise:value -> ${value}`); 626}); 627``` 628 629## settings.unregisterKeyObserver<sup>11+</sup> 630 631unregisterKeyObserver(context: Context, name: string, domainName: string): boolean 632 633Unregisters the observer under the specified domain name. This API returns the result synchronously. 634 635**Model restriction**: This API can be used only in the stage model. 636 637**System capability**: SystemCapability.Applications.Settings.Core 638 639| Name | Type | Mandatory| Description | 640| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 641| context | Context | Yes | Application context. Only UIAbilityContext and ExtensionContext are supported.<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 642| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 643|domainName| string | Yes | Domain name to set.<br>- **domainName.DEVICE_SHARED**:<br> shared device domain<br>- **domainName is domainName.USER_PROPERTY**:<br> user property domain<br>- **domainName.USER_SECURITY**:<br> user security domain (for system applications only)| 644 645**Return value** 646 647| Type | Description | 648| ---------------- | ----------------------------------- | 649| boolean | Whether the observer under the specified domain name is successfully unregistered. Returns **true** if the deregistration is successful; returns **false** otherwise.| 650 651**Example** 652 653```js 654import settings from '@ohos.settings'; 655 656const context: Context = getContext(this); 657let ret = settings.unregisterKeyObserver(context, settings.display.SCREEN_BRIGHTNESS_STATUS, settings.domainName.DEVICE_SHARED); 658``` 659 660## settings.enableAirplaneMode 661 662enableAirplaneMode(enable: boolean, callback: AsyncCallback\<void>): void 663 664Enables or disables airplane mode. This API uses an asynchronous callback to return the result. (Not supported yet.) 665 666**System capability**: SystemCapability.Applications.Settings.Core 667 668**Parameters** 669 670| Name | Type | Mandatory| Description | 671| -------- | -------------------- | ---- | ----------------------------------------------- | 672| enable | boolean | Yes | Whether airplane mode is enabled. **true** means that airplane mode is enabled, and **false** means the opposite.| 673| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 674 675**Example** 676 677```js 678let isEnabled :boolean = true; 679settings.enableAirplaneMode(isEnabled, (err:Error) => { 680 if (err) { 681 console.log('Failed to enable AirplaneMode.'); 682 return; 683 } 684 console.log('Return true if enable.'); 685}) 686``` 687 688## settings.enableAirplaneMode 689 690enableAirplaneMode(enable: boolean): Promise\<void> 691 692Enables or disables airplane mode. This API uses a promise to return the result. (Not supported yet.) 693 694**System capability**: SystemCapability.Applications.Settings.Core 695 696**Parameters** 697 698| Name| Type | Mandatory| Description | 699| ------ | ------- | ---- | ----------------------------------------------- | 700| enable | boolean | Yes | Whether airplane mode is enabled. **true** means that airplane mode is enabled, and **false** means the opposite.| 701 702**Return value** 703 704| Type | Description | 705| -------------- | ------------------------- | 706| Promise\<void> | Promise that returns no value.| 707 708**Example** 709 710```js 711let isEnabled :boolean = true; 712settings.enableAirplaneMode(isEnabled).then(() => { 713 console.log('Succeeded in enabling AirplaneMode.'); 714}).catch((err:Error) => { 715 console.log(`Failed to enable AirplaneMode. Cause: ${err}`); 716}) 717``` 718 719## settings.canShowFloating 720 721canShowFloating(callback: AsyncCallback\<boolean>): void 722 723Checks whether the application can be displayed in a floating window. This API uses an asynchronous callback to return the result. (Not supported yet.) 724 725**System capability**: SystemCapability.Applications.Settings.Core 726 727**Parameters** 728 729| Name | Type | Mandatory| Description | 730| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 731| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result.<br>The value **true** means the application can be displayed in a floating window; **false** means the opposite.| 732 733**Example** 734 735```js 736settings.canShowFloating((err:Error, status: boolean) => { 737 if (err) { 738 console.error(`Failed to Checks whether a specified application can show as float window ${err.message} `); 739 return; 740 } 741 console.log('Checks whether a specified application can show as float window.'); 742}); 743``` 744 745## settings.canShowFloating 746 747canShowFloating(): Promise\<boolean> 748 749Checks whether the application can be displayed in a floating window. This API uses a promise to return the result. (Not supported yet.) 750 751**System capability**: SystemCapability.Applications.Settings.Core 752 753**Return value** 754 755| Type | Description | 756| ----------------- | ------------------------------------------------------------ | 757| Promise\<boolean> | Promise used to return the result.<br>The value **true** means the application can be displayed in a floating window; **false** means the opposite.| 758 759**Example** 760 761```js 762settings.canShowFloating().then((status:boolean) => { 763 console.log('Checks whether a specified application can show as float window.'); 764}); 765``` 766 767## settings.getUriSync<sup>8+</sup> 768 769getUriSync(name: string): string 770 771Obtains the URI of a data item. (Not supported yet.) 772 773**System capability**: SystemCapability.Applications.Settings.Core 774 775**Parameters** 776 777| Name| Type | Mandatory| Description | 778| ------ | ------ | ---- | ------------------------------------------------------------ | 779| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 780 781**Return value** 782 783| Type | Description | 784| ------ | ------------- | 785| string | URI of the data item.| 786 787**Example** 788 789```js 790// Obtain the URI of a data item. 791let uriVar:string = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); 792``` 793 794## settings.getURI<sup>(deprecated)</sup> 795 796getURI(name: string, callback: AsyncCallback\<object>): void 797 798Obtains the URI of a data item. This API uses an asynchronous callback to return the result. (Not supported yet.) 799 800> **NOTE** 801> 802> This API is supported since API version 7 and deprecated since API version 9. No substitute API is provided. 803 804**System capability**: SystemCapability.Applications.Settings.Core 805 806**Parameters** 807 808| Name | Type | Mandatory| Description | 809| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 810| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 811| callback | AsyncCallback\<object> | Yes | Callback used to return the result. Obtains the URI of a data item. | 812 813**Example** 814 815```js 816settings.getURI(settings.display.SCREEN_BRIGHTNESS_STATUS, (uri:string) => { 817 console.log(`callback:uri -> ${JSON.stringify(uri)}`) 818}) 819``` 820 821## settings.getURI<sup>(deprecated)</sup> 822 823getURI(name: string): Promise\<object> 824 825Obtains the URI of a data item. This API uses a promise to return the result. (Not supported yet.) 826 827> **NOTE** 828> 829> This API is supported since API version 7 and deprecated since API version 9. No substitute API is provided. 830 831**System capability**: SystemCapability.Applications.Settings.Core 832 833**Parameters** 834 835| Name| Type | Mandatory| Description | 836| ------ | ------ | ---- | ------------------------------------------------------------ | 837| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 838 839**Return value** 840 841| Type | Description | 842| ---------------- | ------------------------------------ | 843| Promise\<object> | Promise used to return the result. return the URI of the data item.| 844 845**Example** 846 847```js 848settings.getURI(settings.display.SCREEN_BRIGHTNESS_STATUS).then((uri:string) => { 849 console.log(`promise:uri -> ${JSON.stringify(uri)}`) 850}) 851``` 852 853 854 855## settings.getValue<sup>(deprecated)</sup> 856 857getValue(dataAbilityHelper: DataAbilityHelper, name: string, callback: AsyncCallback\<object>): void 858 859Obtains the value of a data item in the database. This API uses an asynchronous callback to return the result. 860 861> **NOTE** 862> 863> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getValue()](#settingsgetvalue10) instead. 864 865**Model restriction**: This API can be used only in the FA model. 866 867**System capability**: SystemCapability.Applications.Settings.Core 868 869**Parameters** 870 871| Name | Type | Mandatory| Description | 872| ----------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 873| dataAbilityHelper | [DataAbilityHelper](../apis-ability-kit/js-apis-inner-ability-dataAbilityHelper.md) | Yes | **DataAbilityHelper** class. | 874| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 875| callback | AsyncCallback\<object> | Yes | Callback used to return the value of the data item. | 876 877**Example** 878 879```js 880import featureAbility from '@ohos.ability.featureAbility'; 881 882let uri:string = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); 883let helper = featureAbility.acquireDataAbilityHelper(uri); 884settings.getValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, (err:Error, value:string) => { 885 if (err) { 886 console.error(`Failed to get the setting. ${err.message} `); 887 return; 888 } 889 console.log(`callback:value -> ${JSON.stringify(value)}`) 890}); 891``` 892 893## settings.getValue<sup>(deprecated)</sup> 894 895getValue(dataAbilityHelper: DataAbilityHelper, name: string): Promise\<object> 896 897Obtains the value of a data item in the database. This API uses a promise to return the result. 898 899> **NOTE** 900> 901> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getValue()](#settingsgetvalue10-1) instead. 902 903**Model restriction**: This API can be used only in the FA model. 904 905**System capability**: SystemCapability.Applications.Settings.Core 906 907**Parameters** 908 909| Name | Type | Mandatory| Description | 910| ----------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 911| dataAbilityHelper | [DataAbilityHelper](../apis-ability-kit/js-apis-inner-ability-dataAbilityHelper.md) | Yes | **DataAbilityHelper** class. | 912| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 913 914**Return value** 915 916| Type | Description | 917| ---------------- | ----------------------------------- | 918| Promise\<object> | Promise used to return the result. return the value of the data item.| 919 920**Example** 921 922```js 923import featureAbility from '@ohos.ability.featureAbility'; 924 925let uri:string = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); 926let helper = featureAbility.acquireDataAbilityHelper(uri); 927settings.getValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS).then((value:string) => { 928 console.log(`promise:value -> ${JSON.stringify(value)}`) 929}); 930``` 931 932## settings.getValueSync<sup>(deprecated)</sup> 933 934getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string 935 936Obtains the value of a data item. Unlike **getValue**, this API returns the result synchronously. 937 938> **NOTE** 939> 940> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getValueSync()](#settingsgetvaluesync10) instead. 941 942**Model restriction**: This API can be used only in the FA model. 943 944**System capability**: SystemCapability.Applications.Settings.Core 945 946**Parameters** 947 948| Name | Type | Mandatory| Description | 949| ----------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 950| dataAbilityHelper | [DataAbilityHelper](../apis-ability-kit/js-apis-inner-ability-dataAbilityHelper.md) | Yes | **DataAbilityHelper** class. | 951| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 952| defValue | string | Yes | Default value, which is returned when the value of a data item is not found in the database. Set this parameter as needed.| 953 954**Return value** 955 956| Type | Description | 957| ------ | ---------------- | 958| string | Value of the data item.| 959 960**Example** 961 962```js 963import featureAbility from '@ohos.ability.featureAbility'; 964 965// Obtain the value of SCREEN_BRIGHTNESS_STATUS (this data item already exists in the database). 966let uri:string = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); 967let helper = featureAbility.acquireDataAbilityHelper(uri); 968let value:string = settings.getValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '10'); 969``` 970 971## settings.setValueSync<sup>(deprecated)</sup> 972 973setValueSync(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean 974 975Sets the value for a data item. Unlike **setValue**, this API returns the result synchronously. 976 977- If the specified data item exists in the database, the **setValueSync** method updates the value of the data item. 978- If the data item does not exist in the database, the **setValueSync** method inserts the data item into the database. 979 980> **NOTE** 981> 982> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setValueSync()](#settingssetvaluesync10) instead. 983 984**Model restriction**: This API can be used only in the FA model. 985 986**Required permissions**: ohos.permission.MANAGE_SETTINGS (available only to system applications) 987 988**System capability**: SystemCapability.Applications.Settings.Core 989 990**Parameters** 991 992| Name | Type | Mandatory| Description | 993| ----------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 994| dataAbilityHelper | [DataAbilityHelper](../apis-ability-kit/js-apis-inner-ability-dataAbilityHelper.md) | Yes | **DataAbilityHelper** class. | 995| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| 996| value | string | Yes | Value of the data item. The value range varies by service. | 997 998**Return value** 999 1000| Type | Description | 1001| ------- | ------------------------------------------------------------ | 1002| boolean | Result indicating whether the value is set successfully. Returns **true** if the value is set successfully; returns **false** otherwise.| 1003 1004**Example** 1005 1006```js 1007import featureAbility from '@ohos.ability.featureAbility'; 1008 1009// Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValueSync API will update its value.) 1010let uri:string = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); 1011let helper = featureAbility.acquireDataAbilityHelper(uri); 1012let ret:string = settings.setValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100'); 1013``` 1014