• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>&nbsp;&nbsp;&nbsp;shared device domain<br>- **domainName.USER_PROPERTY**:<br>&nbsp;&nbsp;&nbsp;user property domain<br>- **domainName.USER_SECURITY**:<br>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;shared device domain<br>- **domainName.USER_PROPERTY**:<br>&nbsp;&nbsp;&nbsp;user property domain<br>- **domainName.USER_SECURITY**:<br>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;shared device domain<br>- **domainName.USER_PROPERTY**:<br>&nbsp;&nbsp;&nbsp;user property domain<br>- **domainName.USER_SECURITY**:<br>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;shared device domain<br>- **domainName.USER_PROPERTY**:<br>&nbsp;&nbsp;&nbsp;user property domain<br>- **domainName.USER_SECURITY**:<br>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;shared device domain<br>- **domainName.USER_PROPERTY**:<br>&nbsp;&nbsp;&nbsp;user property domain<br>- **domainName.USER_SECURITY**:<br>&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;shared device domain<br>- **domainName.USER_PROPERTY**:<br>&nbsp;&nbsp;&nbsp;user property domain<br>- **domainName.USER_SECURITY**:<br>&nbsp;&nbsp;&nbsp;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.openNetworkManagerSettings<sup>18+</sup>
661
662openNetworkManagerSettings(context: Context): Promise\<boolean>
663
664Opens the network manager settings page. This API uses a promise to return the result.
665
666**Atomic service API**: This API can be used in atomic services since API version 18.
667
668**System capability**: SystemCapability.Applications.Settings.Core
669
670**Parameters**
671
672| Name  | Type                  | Mandatory| Description                                                                                                                                                                                                                                                                 |
673| -------- | ---------------------- | ---- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
674| 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).                                                                                                                                                               |
675
676**Return value**
677
678| Type            | Description                               |
679| ---------------- | ----------------------------------- |
680| Promise\<string> | Promise used to return the result. Returns **true** if the operation is successful; returns **false** otherwise.|
681
682**Error codes**
683
684For details about the error codes, see [Settings Error Codes](./errorcode-settings.md).
685
686| ID   | Error Message                   |
687|----------|-------------------------|
688| 14800000 | Parameter error.        |
689| 14800010 | Original service error. |
690
691**Example**
692
693```js
694import settings from '@ohos.settings';
695
696// Redirect to the network manager settings page.
697const context: Context =  getContext(this);
698settings.openNetworkManagerSettings(context).then((status) => {
699  console.log(`callback:return whether settings is open.`)
700});
701```
702
703## settings.enableAirplaneMode
704
705enableAirplaneMode(enable: boolean, callback: AsyncCallback\<void>): void
706
707Enables or disables airplane mode. This API uses an asynchronous callback to return the result. (Not supported yet.)
708
709**System capability**: SystemCapability.Applications.Settings.Core
710
711**Parameters**
712
713| Name  | Type                | Mandatory| Description                                           |
714| -------- | -------------------- | ---- | ----------------------------------------------- |
715| enable   | boolean              | Yes  | Whether airplane mode is enabled. **true** means that airplane mode is enabled, and **false** means the opposite.|
716| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.                                     |
717
718**Example**
719
720```js
721let isEnabled :boolean = true;
722settings.enableAirplaneMode(isEnabled, (err:Error) => {
723    if (err) {
724        console.log('Failed to enable AirplaneMode.');
725        return;
726    }
727    console.log('Return true if enable.');
728})
729```
730
731## settings.enableAirplaneMode
732
733enableAirplaneMode(enable: boolean): Promise\<void>
734
735Enables or disables airplane mode. This API uses a promise to return the result. (Not supported yet.)
736
737**System capability**: SystemCapability.Applications.Settings.Core
738
739**Parameters**
740
741| Name| Type   | Mandatory| Description                                           |
742| ------ | ------- | ---- | ----------------------------------------------- |
743| enable | boolean | Yes  | Whether airplane mode is enabled. **true** means that airplane mode is enabled, and **false** means the opposite.|
744
745**Return value**
746
747| Type          | Description                     |
748| -------------- | ------------------------- |
749| Promise\<void> | Promise that returns no value.|
750
751**Example**
752
753```js
754let isEnabled :boolean = true;
755settings.enableAirplaneMode(isEnabled).then(() => {
756  console.log('Succeeded in enabling AirplaneMode.');
757}).catch((err:Error) => {
758  console.log(`Failed to enable AirplaneMode. Cause: ${err}`);
759})
760```
761
762## settings.canShowFloating
763
764canShowFloating(callback: AsyncCallback\<boolean>): void
765
766Checks whether the application can be displayed in a floating window. This API uses an asynchronous callback to return the result. (Not supported yet.)
767
768**System capability**: SystemCapability.Applications.Settings.Core
769
770**Parameters**
771
772| Name  | Type                   | Mandatory| Description                                                        |
773| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
774| 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.|
775
776**Example**
777
778```js
779settings.canShowFloating((err:Error, status: boolean) => {
780  if (err) {
781    console.error(`Failed to Checks whether a specified application can show as float window ${err.message} `);
782    return;
783  }
784  console.log('Checks whether a specified application can show as float window.');
785});
786```
787
788## settings.canShowFloating
789
790canShowFloating(): Promise\<boolean>
791
792Checks whether the application can be displayed in a floating window. This API uses a promise to return the result. (Not supported yet.)
793
794**System capability**: SystemCapability.Applications.Settings.Core
795
796**Return value**
797
798| Type             | Description                                                        |
799| ----------------- | ------------------------------------------------------------ |
800| 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.|
801
802**Example**
803
804```js
805settings.canShowFloating().then((status:boolean) => {
806    console.log('Checks whether a specified application can show as float window.');
807});
808```
809
810## settings.getUriSync<sup>8+</sup>
811
812getUriSync(name: string): string
813
814Obtains the URI of a data item. (Not supported yet.)
815
816**System capability**: SystemCapability.Applications.Settings.Core
817
818**Parameters**
819
820| Name| Type  | Mandatory| Description                                                        |
821| ------ | ------ | ---- | ------------------------------------------------------------ |
822| 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|
823
824**Return value**
825
826| Type  | Description         |
827| ------ | ------------- |
828| string | URI of the data item.|
829
830**Example**
831
832```js
833// Obtain the URI of a data item.
834let uriVar:string = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS);
835```
836
837## settings.getURI<sup>(deprecated)</sup>
838
839getURI(name: string, callback: AsyncCallback\<object>): void
840
841Obtains the URI of a data item. This API uses an asynchronous callback to return the result. (Not supported yet.)
842
843> **NOTE**
844>
845> This API is supported since API version 7 and deprecated since API version 9. No substitute API is provided.
846
847**System capability**: SystemCapability.Applications.Settings.Core
848
849**Parameters**
850
851| Name  | Type                  | Mandatory| Description                                                        |
852| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
853| 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|
854| callback | AsyncCallback\<object> | Yes  | Callback used to return the result. Obtains the URI of a data item.                                 |
855
856**Example**
857
858```js
859settings.getURI(settings.display.SCREEN_BRIGHTNESS_STATUS, (uri:string) => {
860    console.log(`callback:uri -> ${JSON.stringify(uri)}`)
861})
862```
863
864## settings.getURI<sup>(deprecated)</sup>
865
866getURI(name: string): Promise\<object>
867
868Obtains the URI of a data item. This API uses a promise to return the result. (Not supported yet.)
869
870> **NOTE**
871>
872> This API is supported since API version 7 and deprecated since API version 9. No substitute API is provided.
873
874**System capability**: SystemCapability.Applications.Settings.Core
875
876**Parameters**
877
878| Name| Type  | Mandatory| Description                                                        |
879| ------ | ------ | ---- | ------------------------------------------------------------ |
880| 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|
881
882**Return value**
883
884| Type            | Description                                |
885| ---------------- | ------------------------------------ |
886| Promise\<object> | Promise used to return the result. return the URI of the data item.|
887
888**Example**
889
890```js
891settings.getURI(settings.display.SCREEN_BRIGHTNESS_STATUS).then((uri:string) => {
892    console.log(`promise:uri -> ${JSON.stringify(uri)}`)
893})
894```
895
896
897
898## settings.getValue<sup>(deprecated)</sup>
899
900getValue(dataAbilityHelper: DataAbilityHelper, name: string, callback: AsyncCallback\<object>): void
901
902Obtains the value of a data item in the database. This API uses an asynchronous callback to return the result.
903
904> **NOTE**
905>
906> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getValue()](#settingsgetvalue10) instead.
907
908**Model restriction**: This API can be used only in the FA model.
909
910**System capability**: SystemCapability.Applications.Settings.Core
911
912**Parameters**
913
914| Name           | Type                                                        | Mandatory| Description                                                        |
915| ----------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
916| dataAbilityHelper | [DataAbilityHelper](../apis-ability-kit/js-apis-inner-ability-dataAbilityHelper.md) | Yes  | **DataAbilityHelper** class.                                            |
917| 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|
918| callback          | AsyncCallback\<object>                                       | Yes  | Callback used to 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, (err:Error, value:string) => {
928    if (err) {
929        console.error(`Failed to get the setting. ${err.message} `);
930        return;
931    }
932    console.log(`callback:value -> ${JSON.stringify(value)}`)
933});
934```
935
936## settings.getValue<sup>(deprecated)</sup>
937
938getValue(dataAbilityHelper: DataAbilityHelper, name: string): Promise\<object>
939
940Obtains the value of a data item in the database. This API uses a promise to return the result.
941
942> **NOTE**
943>
944> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getValue()](#settingsgetvalue10-1) instead.
945
946**Model restriction**: This API can be used only in the FA model.
947
948**System capability**: SystemCapability.Applications.Settings.Core
949
950**Parameters**
951
952| Name           | Type                                                        | Mandatory| Description                                                        |
953| ----------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
954| dataAbilityHelper | [DataAbilityHelper](../apis-ability-kit/js-apis-inner-ability-dataAbilityHelper.md) | Yes  | **DataAbilityHelper** class.                                            |
955| 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|
956
957**Return value**
958
959| Type            | Description                               |
960| ---------------- | ----------------------------------- |
961| Promise\<object> | Promise used to return the result. return the value of the data item.|
962
963**Example**
964
965```js
966import featureAbility from '@ohos.ability.featureAbility';
967
968let uri:string = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS);
969let helper = featureAbility.acquireDataAbilityHelper(uri);
970settings.getValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS).then((value:string) => {
971    console.log(`promise:value -> ${JSON.stringify(value)}`)
972});
973```
974
975## settings.getValueSync<sup>(deprecated)</sup>
976
977getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string
978
979Obtains the value of a data item. Unlike **getValue**, this API returns the result synchronously.
980
981> **NOTE**
982>
983> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getValueSync()](#settingsgetvaluesync10) instead.
984
985**Model restriction**: This API can be used only in the FA model.
986
987**System capability**: SystemCapability.Applications.Settings.Core
988
989**Parameters**
990
991| Name           | Type                                                        | Mandatory| Description                                                        |
992| ----------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
993| dataAbilityHelper | [DataAbilityHelper](../apis-ability-kit/js-apis-inner-ability-dataAbilityHelper.md) | Yes  | **DataAbilityHelper** class.                                            |
994| 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|
995| 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.|
996
997**Return value**
998
999| Type  | Description            |
1000| ------ | ---------------- |
1001| string | Value of the data item.|
1002
1003**Example**
1004
1005```js
1006import featureAbility from '@ohos.ability.featureAbility';
1007
1008// Obtain the value of SCREEN_BRIGHTNESS_STATUS (this data item already exists in the database).
1009let uri:string = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS);
1010let helper = featureAbility.acquireDataAbilityHelper(uri);
1011let value:string = settings.getValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '10');
1012```
1013
1014## settings.setValueSync<sup>(deprecated)</sup>
1015
1016setValueSync(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean
1017
1018Sets the value for a data item. Unlike **setValue**, this API returns the result synchronously.
1019
1020- If the specified data item exists in the database, the **setValueSync** method updates the value of the data item.
1021- If the data item does not exist in the database, the **setValueSync** method inserts the data item into the database.
1022
1023> **NOTE**
1024>
1025> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setValueSync()](#settingssetvaluesync10) instead.
1026
1027**Model restriction**: This API can be used only in the FA model.
1028
1029**Required permissions**: ohos.permission.MANAGE_SETTINGS (available only to system applications)
1030
1031**System capability**: SystemCapability.Applications.Settings.Core
1032
1033**Parameters**
1034
1035| Name           | Type                                                        | Mandatory| Description                                                        |
1036| ----------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1037| dataAbilityHelper | [DataAbilityHelper](../apis-ability-kit/js-apis-inner-ability-dataAbilityHelper.md) | Yes  | **DataAbilityHelper** class.                                            |
1038| 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|
1039| value             | string                                                       | Yes  | Value of the data item. The value range varies by service.                      |
1040
1041**Return value**
1042
1043| Type   | Description                                                        |
1044| ------- | ------------------------------------------------------------ |
1045| boolean | Result indicating whether the value is set successfully. Returns **true** if the value is set successfully; returns **false** otherwise.|
1046
1047**Example**
1048
1049```js
1050import featureAbility from '@ohos.ability.featureAbility';
1051
1052// Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValueSync API will update its value.)
1053let uri:string = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS);
1054let helper = featureAbility.acquireDataAbilityHelper(uri);
1055let ret:string = settings.setValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100');
1056```
1057