1e41f4b71Sopenharmony_ci# Preferences
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Overview
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ciThe **Preferences** module provides APIs for key-value (KV) data processing, including querying, modifying, and persisting KV data.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci**Since**: 13
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Summary
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci### Files
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci| Name| Description|
19e41f4b71Sopenharmony_ci| -------- | -------- |
20e41f4b71Sopenharmony_ci| [oh_preferences.h](oh__preferences_8h.md) | Provides APIs and structs for accessing the **Preferences** object.|
21e41f4b71Sopenharmony_ci| [oh_preferences_option.h](oh__preferences__option_8h.md) | Provides APIs and structs for accessing the **PreferencesOption** object.|
22e41f4b71Sopenharmony_ci| [oh_preferences_value.h](oh__preferences__value_8h.md) | Provides APIs, enums, and structs for accessing the **PreferencesValue** object.|
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci### Types
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci| Name| Description|
28e41f4b71Sopenharmony_ci| -------- | -------- |
29e41f4b71Sopenharmony_ci| typedef struct [OH_Preferences](#oh_preferences) [OH_Preferences](#oh_preferences) | Defines a struct for a **Preferences** object.|
30e41f4b71Sopenharmony_ci| typedef void(\* [OH_PreferencesDataObserver](#oh_preferencesdataobserver)) (void \*context, const [OH_PreferencesPair](#oh_preferencespair) \*pairs, uint32_t count) | Defines a struct for the callback for data changes.|
31e41f4b71Sopenharmony_ci| typedef enum [OH_Preferences_ErrCode](#oh_preferences_errcode) [OH_Preferences_ErrCode](#oh_preferences_errcode) | Defines an enum for error codes.|
32e41f4b71Sopenharmony_ci| typedef struct [OH_PreferencesOption](#oh_preferencesoption) [OH_PreferencesOption](#oh_preferencesoption) | Defines a struct for **Preferences** configuration.|
33e41f4b71Sopenharmony_ci| typedef enum [Preference_ValueType](#preference_valuetype) [Preference_ValueType](#preference_valuetype) | Defines an enum for types of **PreferencesValue**.|
34e41f4b71Sopenharmony_ci| typedef struct [OH_PreferencesPair](#oh_preferencespair) [OH_PreferencesPair](#oh_preferencespair) | Defines a struct for the Preferences data in KV format.|
35e41f4b71Sopenharmony_ci| typedef struct [OH_PreferencesValue](#oh_preferencesvalue) [OH_PreferencesValue](#oh_preferencesvalue) | Defines the struct for a **PreferencesValue** object.|
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci### Enums
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci| Name| Description|
41e41f4b71Sopenharmony_ci| -------- | -------- |
42e41f4b71Sopenharmony_ci| [OH_Preferences_ErrCode](#oh_preferences_errcode-1) {<br>PREFERENCES_OK = 0, PREFERENCES_ERROR_INVALID_PARAM = 401, PREFERENCES_ERROR_NOT_SUPPORTED = 801, PREFERENCES_ERROR_BASE = 15500000,<br>PREFERENCES_ERROR_DELETE_FILE = 15500010, PREFERENCES_ERROR_STORAGE = 15500011, PREFERENCES_ERROR_MALLOC = 15500012, PREFERENCES_ERROR_KEY_NOT_FOUND = 15500013,<br>PREFERENCES_ERROR_GET_DATAOBSMGRCLIENT = 15500019<br>} | Enumerates the error codes.|
43e41f4b71Sopenharmony_ci| [Preference_ValueType](#preference_valuetype-1) {<br>PREFERENCE_TYPE_NULL = 0, PREFERENCE_TYPE_INT, PREFERENCE_TYPE_BOOL, PREFERENCE_TYPE_STRING,<br>PREFERENCE_TYPE_BUTT<br>} | Enumerates the types of **PreferencesValue**.|
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci### Functions
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci| Name| Description|
49e41f4b71Sopenharmony_ci| -------- | -------- |
50e41f4b71Sopenharmony_ci| [OH_Preferences](#oh_preferences) \* [OH_Preferences_Open](#oh_preferences_open) ([OH_PreferencesOption](#oh_preferencesoption) \*option, int \*errCode) | Opens a **Preferences** instance and creates a pointer to it. If the pointer is no longer required, use [OH_Preferences_Close][OH_Preferences_Close](#oh_preferences_close) to close the instance.|
51e41f4b71Sopenharmony_ci| int [OH_Preferences_Close](#oh_preferences_close) ([OH_Preferences](#oh_preferences) \*preference) | Closes a **Preferences** instance.|
52e41f4b71Sopenharmony_ci| int [OH_Preferences_GetInt](#oh_preferences_getint) ([OH_Preferences](#oh_preferences) \*preference, const char \*key, int \*value) | Obtains an integer corresponding to the specified key in a **Preferences** instance.|
53e41f4b71Sopenharmony_ci| int [OH_Preferences_GetBool](#oh_preferences_getbool) ([OH_Preferences](#oh_preferences) \*preference, const char \*key, bool \*value) | Obtains a Boolean value corresponding to the specified key in a **Preferences** instance.|
54e41f4b71Sopenharmony_ci| int [OH_Preferences_GetString](#oh_preferences_getstring) ([OH_Preferences](#oh_preferences) \*preference, const char \*key, char \*\*value, uint32_t \*valueLen) | Obtains a string corresponding to the specified key in a **Preferences** instance.|
55e41f4b71Sopenharmony_ci| void [OH_Preferences_FreeString](#oh_preferences_freestring) (char \*string) | Releases a string.|
56e41f4b71Sopenharmony_ci| int [OH_Preferences_SetInt](#oh_preferences_setint) ([OH_Preferences](#oh_preferences) \*preference, const char \*key, int value) | Sets an integer based on the specified key in a **Preferences** instance.|
57e41f4b71Sopenharmony_ci| int [OH_Preferences_SetBool](#oh_preferences_setbool) ([OH_Preferences](#oh_preferences) \*preference, const char \*key, bool value) | Sets a Boolean value based on the specified key in a **Preferences** instance.|
58e41f4b71Sopenharmony_ci| int [OH_Preferences_SetString](#oh_preferences_setstring) ([OH_Preferences](#oh_preferences) \*preference, const char \*key, const char \*value) | Sets a string based on the specified key in a **Preferences** instance.|
59e41f4b71Sopenharmony_ci| int [OH_Preferences_Delete](#oh_preferences_delete) ([OH_Preferences](#oh_preferences) \*preference, const char \*key) | Deletes the KV data corresponding to the specified key from a **Preferences** instance.|
60e41f4b71Sopenharmony_ci| int [OH_Preferences_RegisterDataObserver](#oh_preferences_registerdataobserver) ([OH_Preferences](#oh_preferences) \*preference, void \*context, [OH_PreferencesDataObserver](#oh_preferencesdataobserver) observer, const char \*keys[], uint32_t keyCount) | Subscribes to data changes of the specified keys. If the value of the specified key changes, a callback will be invoked after **OH_Preferences_Close ()** is called.|
61e41f4b71Sopenharmony_ci| int [OH_Preferences_UnregisterDataObserver](#oh_preferences_unregisterdataobserver) ([OH_Preferences](#oh_preferences) \*preference, void \*context, [OH_PreferencesDataObserver](#oh_preferencesdataobserver) observer, const char \*keys[], uint32_t keyCount) | Unsubscribes from data changes of the specified keys.|
62e41f4b71Sopenharmony_ci| [OH_PreferencesOption](#oh_preferencesoption) \* [OH_PreferencesOption_Create](#oh_preferencesoption_create) (void) | Creates an [OH_PreferencesOption](#oh_preferencesoption) instance and a pointer to it. If this pointer is no longer required, use [OH_PreferencesOption_Destroy](#oh_preferencesoption_destroy) to destroy it. Otherwise, memory leaks may occur.|
63e41f4b71Sopenharmony_ci| int [OH_PreferencesOption_SetFileName](#oh_preferencesoption_setfilename) ([OH_PreferencesOption](#oh_preferencesoption) \*option, const char \*fileName) | Sets the file name for an [OH_PreferencesOption](#oh_preferencesoption) instance.|
64e41f4b71Sopenharmony_ci| int [OH_PreferencesOption_SetBundleName](#oh_preferencesoption_setbundlename) ([OH_PreferencesOption](#oh_preferencesoption) \*option, const char \*bundleName) | Sets the bundle name for an [OH_PreferencesOption](#oh_preferencesoption) instance.|
65e41f4b71Sopenharmony_ci| int [OH_PreferencesOption_SetDataGroupId](#oh_preferencesoption_setdatagroupid) ([OH_PreferencesOption](#oh_preferencesoption) \*option, const char \*dataGroupId) | Sets the application group ID for an [OH_PreferencesOption](#oh_preferencesoption) instance.|
66e41f4b71Sopenharmony_ci| int [OH_PreferencesOption_Destroy](#oh_preferencesoption_destroy) ([OH_PreferencesOption](#oh_preferencesoption) \*option) | Destroys an [OH_PreferencesOption](#oh_preferencesoption) instance.|
67e41f4b71Sopenharmony_ci| const char \* [OH_PreferencesPair_GetKey](#oh_preferencespair_getkey) (const [OH_PreferencesPair](#oh_preferencespair) \*pairs, uint32_t index) | Obtains the key based on the specified index from the KV data.|
68e41f4b71Sopenharmony_ci| const [OH_PreferencesValue](#oh_preferencesvalue) \* [OH_PreferencesPair_GetPreferencesValue](#oh_preferencespair_getpreferencesvalue) (const [OH_PreferencesPair](#oh_preferencespair) \*pairs, uint32_t index) | Obtains the value based on the specified index from the KV pairs.|
69e41f4b71Sopenharmony_ci| [Preference_ValueType](#preference_valuetype) [OH_PreferencesValue_GetValueType](#oh_preferencesvalue_getvaluetype) (const [OH_PreferencesValue](#oh_preferencesvalue) \*object) | Obtains the data type of a **PreferencesValue** instance.|
70e41f4b71Sopenharmony_ci| int [OH_PreferencesValue_GetInt](#oh_preferencesvalue_getint) (const [OH_PreferencesValue](#oh_preferencesvalue) \*object, int \*value) | Obtains an integer value from an [OH_PreferencesValue](#oh_preferencesvalue) instance.|
71e41f4b71Sopenharmony_ci| int [OH_PreferencesValue_GetBool](#oh_preferencesvalue_getbool) (const [OH_PreferencesValue](#oh_preferencesvalue) \*object, bool \*value) | Obtains a Boolean value from an [OH_PreferencesValue](#oh_preferencesvalue) instance.|
72e41f4b71Sopenharmony_ci| int [OH_PreferencesValue_GetString](#oh_preferencesvalue_getstring) (const [OH_PreferencesValue](#oh_preferencesvalue) \*object, char \*\*value, uint32_t \*valueLen) | Obtains a string from an [OH_PreferencesValue](#oh_preferencesvalue) instance.|
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci## Type Description
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci### OH_Preferences
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci```
81e41f4b71Sopenharmony_citypedef struct OH_Preferences OH_Preferences
82e41f4b71Sopenharmony_ci```
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Description**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ciRepresents a **Preferences** object.
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**Since**: 13
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci### OH_Preferences_ErrCode
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci```
94e41f4b71Sopenharmony_citypedef enum OH_Preferences_ErrCode OH_Preferences_ErrCode
95e41f4b71Sopenharmony_ci```
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci**Description**
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ciDefines an enum for error codes.
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci**Since**: 13
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci### OH_PreferencesDataObserver
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci```
107e41f4b71Sopenharmony_citypedef void(*OH_PreferencesDataObserver) (void *context, const OH_PreferencesPair *pairs, uint32_t count)
108e41f4b71Sopenharmony_ci```
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci**Description**
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ciDefines a struct for the callback used to return data changes.
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci**Since**: 13
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci**Parameters**
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci| Name| Description|
119e41f4b71Sopenharmony_ci| -------- | -------- |
120e41f4b71Sopenharmony_ci| context | Pointer to the application context.|
121e41f4b71Sopenharmony_ci| pairs | Pointer to the changed KV data.|
122e41f4b71Sopenharmony_ci| count | Number of KV pairs changed.|
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**See**
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci[OH_PreferencesPair](#oh_preferencespair)
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci### OH_PreferencesOption
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci```
132e41f4b71Sopenharmony_citypedef struct OH_PreferencesOption OH_PreferencesOption
133e41f4b71Sopenharmony_ci```
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci**Description**
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ciDefines a struct for **Preferences** configuration.
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci**Since**: 13
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci### OH_PreferencesPair
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci```
145e41f4b71Sopenharmony_citypedef struct OH_PreferencesPair OH_PreferencesPair
146e41f4b71Sopenharmony_ci```
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci**Description**
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ciDefines a struct for the **Preferences** data in KV format.
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci**Since**: 13
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci### OH_PreferencesValue
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci```
158e41f4b71Sopenharmony_citypedef struct OH_PreferencesValue OH_PreferencesValue
159e41f4b71Sopenharmony_ci```
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci**Description**
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ciDefines the struct for a **PreferencesValue** object.
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci**Since**: 13
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci### Preference_ValueType
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci```
171e41f4b71Sopenharmony_citypedef enum Preference_ValueType Preference_ValueType
172e41f4b71Sopenharmony_ci```
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci**Description**
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ciDefines an enum for types of **PreferencesValue**.
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**Since**: 13
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci## Enum Description
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci### OH_Preferences_ErrCode
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci```
187e41f4b71Sopenharmony_cienum OH_Preferences_ErrCode
188e41f4b71Sopenharmony_ci```
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci**Description**
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ciEnumerates the error codes.
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci**Since**: 13
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci| Enumerated Value| Description|
197e41f4b71Sopenharmony_ci| -------- | -------- |
198e41f4b71Sopenharmony_ci| PREFERENCES_OK | The operation is successful.|
199e41f4b71Sopenharmony_ci| PREFERENCES_ERROR_INVALID_PARAM | Invalid parameter.|
200e41f4b71Sopenharmony_ci| PREFERENCES_ERROR_NOT_SUPPORTED | The system capability is not supported.|
201e41f4b71Sopenharmony_ci| PREFERENCES_ERROR_BASE | Base error code.|
202e41f4b71Sopenharmony_ci| PREFERENCES_ERROR_DELETE_FILE | Failed to delete the file.|
203e41f4b71Sopenharmony_ci| PREFERENCES_ERROR_STORAGE | The storage is abnormal.|
204e41f4b71Sopenharmony_ci| PREFERENCES_ERROR_MALLOC | Failed to allocate memory.|
205e41f4b71Sopenharmony_ci| PREFERENCES_ERROR_KEY_NOT_FOUND | The key does not exist.|
206e41f4b71Sopenharmony_ci| PREFERENCES_ERROR_GET_DATAOBSMGRCLIENT | Failed to obtain the data change subscription service.|
207e41f4b71Sopenharmony_ci
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci### Preference_ValueType
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ci```
212e41f4b71Sopenharmony_cienum Preference_ValueType
213e41f4b71Sopenharmony_ci```
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ci**Description**
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ciEnumerates the types of **PreferencesValue**.
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci**Since**: 13
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci| Enumerated Value| Description|
222e41f4b71Sopenharmony_ci| -------- | -------- |
223e41f4b71Sopenharmony_ci| PREFERENCE_TYPE_NULL | Null.|
224e41f4b71Sopenharmony_ci| PREFERENCE_TYPE_INT | Integer.|
225e41f4b71Sopenharmony_ci| PREFERENCE_TYPE_BOOL | Boolean.|
226e41f4b71Sopenharmony_ci| PREFERENCE_TYPE_STRING | String.|
227e41f4b71Sopenharmony_ci| PREFERENCE_TYPE_BUTT | End type.|
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci## Function Description
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci### OH_Preferences_Close()
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci```
236e41f4b71Sopenharmony_ciint OH_Preferences_Close (OH_Preferences *preference)
237e41f4b71Sopenharmony_ci```
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_ci**Description**
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_ciCloses a **Preferences** instance.
242e41f4b71Sopenharmony_ci
243e41f4b71Sopenharmony_ci**Since**: 13
244e41f4b71Sopenharmony_ci
245e41f4b71Sopenharmony_ci**Parameters**
246e41f4b71Sopenharmony_ci
247e41f4b71Sopenharmony_ci| Name| Description|
248e41f4b71Sopenharmony_ci| -------- | -------- |
249e41f4b71Sopenharmony_ci| preference | Pointer to the [OH_Preferences](#oh_preferences) instance to close.|
250e41f4b71Sopenharmony_ci
251e41f4b71Sopenharmony_ci**Returns**
252e41f4b71Sopenharmony_ci
253e41f4b71Sopenharmony_ciReturns [OH_Preferences_ErrCode](#oh_preferences_errcode).
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
258e41f4b71Sopenharmony_ci
259e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci**See**
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_ci### OH_Preferences_Delete()
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci```
273e41f4b71Sopenharmony_ciint OH_Preferences_Delete (OH_Preferences *preference, const char *key )
274e41f4b71Sopenharmony_ci```
275e41f4b71Sopenharmony_ci
276e41f4b71Sopenharmony_ci**Description**
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ciDeletes the KV data corresponding to the specified key from a **Preferences** instance.
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ci**Since**: 13
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci**Parameters**
283e41f4b71Sopenharmony_ci
284e41f4b71Sopenharmony_ci| Name| Description|
285e41f4b71Sopenharmony_ci| -------- | -------- |
286e41f4b71Sopenharmony_ci| preference | Pointer to the target [OH_Preferences](#oh_preferences) instance.|
287e41f4b71Sopenharmony_ci| key | Pointer to the key of the KV pair to delete.|
288e41f4b71Sopenharmony_ci
289e41f4b71Sopenharmony_ci**Returns**
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ciReturns the error code.
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
296e41f4b71Sopenharmony_ci
297e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci**See**
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
304e41f4b71Sopenharmony_ci
305e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
306e41f4b71Sopenharmony_ci
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ci### OH_Preferences_FreeString()
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ci```
311e41f4b71Sopenharmony_civoid OH_Preferences_FreeString (char *string)
312e41f4b71Sopenharmony_ci```
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_ci**Description**
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ciReleases a string.
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci**Since**: 13
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci**Parameters**
321e41f4b71Sopenharmony_ci
322e41f4b71Sopenharmony_ci| Name| Description|
323e41f4b71Sopenharmony_ci| -------- | -------- |
324e41f4b71Sopenharmony_ci| string | Pointer to the string to release.|
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci**See**
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
329e41f4b71Sopenharmony_ci
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci### OH_Preferences_GetBool()
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci```
334e41f4b71Sopenharmony_ciint OH_Preferences_GetBool (OH_Preferences *preference, const char *key, bool *value )
335e41f4b71Sopenharmony_ci```
336e41f4b71Sopenharmony_ci
337e41f4b71Sopenharmony_ci**Description**
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ciObtains a Boolean value corresponding to the specified key in a **Preferences** instance.
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci**Since**: 13
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci**Parameters**
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci| Name| Description|
346e41f4b71Sopenharmony_ci| -------- | -------- |
347e41f4b71Sopenharmony_ci| preference | Pointer to the target [OH_Preferences](#oh_preferences) instance.|
348e41f4b71Sopenharmony_ci| key | Pointer to the key of the value to obtain.|
349e41f4b71Sopenharmony_ci| value | Pointer to the Boolean value obtained.|
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_ci**Returns**
352e41f4b71Sopenharmony_ci
353e41f4b71Sopenharmony_ciReturns the error code.
354e41f4b71Sopenharmony_ci
355e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_KEY_NOT_FOUND** if the specified key does not exist.
364e41f4b71Sopenharmony_ci
365e41f4b71Sopenharmony_ci**See**
366e41f4b71Sopenharmony_ci
367e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
368e41f4b71Sopenharmony_ci
369e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
370e41f4b71Sopenharmony_ci
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_ci### OH_Preferences_GetInt()
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ci```
375e41f4b71Sopenharmony_ciint OH_Preferences_GetInt (OH_Preferences *preference, const char *key, int *value )
376e41f4b71Sopenharmony_ci```
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci**Description**
379e41f4b71Sopenharmony_ci
380e41f4b71Sopenharmony_ciObtains an integer corresponding to the specified key in a **Preferences** instance.
381e41f4b71Sopenharmony_ci
382e41f4b71Sopenharmony_ci**Since**: 13
383e41f4b71Sopenharmony_ci
384e41f4b71Sopenharmony_ci**Parameters**
385e41f4b71Sopenharmony_ci
386e41f4b71Sopenharmony_ci| Name| Description|
387e41f4b71Sopenharmony_ci| -------- | -------- |
388e41f4b71Sopenharmony_ci| preference | Pointer to the target [OH_Preferences](#oh_preferences) instance.|
389e41f4b71Sopenharmony_ci| key | Pointer to the key of the value to obtain.|
390e41f4b71Sopenharmony_ci| value | Pointer to the integer value obtained.|
391e41f4b71Sopenharmony_ci
392e41f4b71Sopenharmony_ci**Returns**
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ciReturns the error code.
395e41f4b71Sopenharmony_ci
396e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_KEY_NOT_FOUND** if the specified key does not exist.
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci**See**
407e41f4b71Sopenharmony_ci
408e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
409e41f4b71Sopenharmony_ci
410e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
411e41f4b71Sopenharmony_ci
412e41f4b71Sopenharmony_ci
413e41f4b71Sopenharmony_ci### OH_Preferences_GetString()
414e41f4b71Sopenharmony_ci
415e41f4b71Sopenharmony_ci```
416e41f4b71Sopenharmony_ciint OH_Preferences_GetString (OH_Preferences *preference, const char *key, char **value, uint32_t *valueLen )
417e41f4b71Sopenharmony_ci```
418e41f4b71Sopenharmony_ci
419e41f4b71Sopenharmony_ci**Description**
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ciObtains a string corresponding to the specified key in a **Preferences** instance.
422e41f4b71Sopenharmony_ci
423e41f4b71Sopenharmony_ci**Since**: 13
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_ci**Parameters**
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ci| Name| Description|
428e41f4b71Sopenharmony_ci| -------- | -------- |
429e41f4b71Sopenharmony_ci| preference | Pointer to the target [OH_Preferences](#oh_preferences) instance.|
430e41f4b71Sopenharmony_ci| key | Pointer to the key of the value to obtain.|
431e41f4b71Sopenharmony_ci| value | Double pointer to the string obtained. If the string is not required, you can use [OH_Preferences_FreeString](#oh_preferences_freestring) to free the string (release the memory occupied by the string).|
432e41f4b71Sopenharmony_ci| valueLen | Pointer to the length of the string obtained.|
433e41f4b71Sopenharmony_ci
434e41f4b71Sopenharmony_ci**Returns**
435e41f4b71Sopenharmony_ci
436e41f4b71Sopenharmony_ciReturns the error code.
437e41f4b71Sopenharmony_ci
438e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
439e41f4b71Sopenharmony_ci
440e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
441e41f4b71Sopenharmony_ci
442e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
443e41f4b71Sopenharmony_ci
444e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
445e41f4b71Sopenharmony_ci
446e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_KEY_NOT_FOUND** if the specified key does not exist.
447e41f4b71Sopenharmony_ci
448e41f4b71Sopenharmony_ci**See**
449e41f4b71Sopenharmony_ci
450e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
451e41f4b71Sopenharmony_ci
452e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
453e41f4b71Sopenharmony_ci
454e41f4b71Sopenharmony_ci
455e41f4b71Sopenharmony_ci### OH_Preferences_Open()
456e41f4b71Sopenharmony_ci
457e41f4b71Sopenharmony_ci```
458e41f4b71Sopenharmony_ciOH_Preferences* OH_Preferences_Open (OH_PreferencesOption *option, int *errCode )
459e41f4b71Sopenharmony_ci```
460e41f4b71Sopenharmony_ci
461e41f4b71Sopenharmony_ci**Description**
462e41f4b71Sopenharmony_ci
463e41f4b71Sopenharmony_ciOpens a **Preferences** instance and creates a pointer to it. If the pointer is no longer required, use [OH_Preferences_Close](#oh_preferences_close) to close the instance.
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_ci**Since**: 13
466e41f4b71Sopenharmony_ci
467e41f4b71Sopenharmony_ci**Parameters**
468e41f4b71Sopenharmony_ci
469e41f4b71Sopenharmony_ci| Name| Description|
470e41f4b71Sopenharmony_ci| -------- | -------- |
471e41f4b71Sopenharmony_ci| option | Pointer to the [OH_PreferencesOption](#oh_preferencesoption) instance.|
472e41f4b71Sopenharmony_ci| errCode | Pointer to the error code returned. For details, see [OH_Preferences_ErrCode](#oh_preferences_errcode).|
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci**Returns**
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ciReturns the [OH_Preferences](#oh_preferences) instance opened if the operation is successful; returns a null pointer otherwise.
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_ci**See**
479e41f4b71Sopenharmony_ci
480e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci[OH_PreferencesOption](#oh_preferencesoption)
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
485e41f4b71Sopenharmony_ci
486e41f4b71Sopenharmony_ci
487e41f4b71Sopenharmony_ci### OH_Preferences_RegisterDataObserver()
488e41f4b71Sopenharmony_ci
489e41f4b71Sopenharmony_ci```
490e41f4b71Sopenharmony_ciint OH_Preferences_RegisterDataObserver (OH_Preferences *preference, void *context, OH_PreferencesDataObserver observer, const char *keys[], uint32_t keyCount )
491e41f4b71Sopenharmony_ci```
492e41f4b71Sopenharmony_ci
493e41f4b71Sopenharmony_ci**Description**
494e41f4b71Sopenharmony_ci
495e41f4b71Sopenharmony_ciSubscribes to data changes of the specified keys. If the value of the specified key changes, a callback will be invoked after **OH_Preferences_Close ()** is called.
496e41f4b71Sopenharmony_ci
497e41f4b71Sopenharmony_ci**Since**: 13
498e41f4b71Sopenharmony_ci
499e41f4b71Sopenharmony_ci**Parameters**
500e41f4b71Sopenharmony_ci
501e41f4b71Sopenharmony_ci| Name| Description|
502e41f4b71Sopenharmony_ci| -------- | -------- |
503e41f4b71Sopenharmony_ci| preference | Pointer to the target [OH_Preferences](#oh_preferences) instance.|
504e41f4b71Sopenharmony_ci| context | Pointer to the application context.|
505e41f4b71Sopenharmony_ci| observer | [OH_PreferencesDataObserver](#oh_preferencesdataobserver) callback to be invoked when the data changes.|
506e41f4b71Sopenharmony_ci| keys | Pointer to the keys of the data to be observed.|
507e41f4b71Sopenharmony_ci| keyCount | Number of keys observed.|
508e41f4b71Sopenharmony_ci
509e41f4b71Sopenharmony_ci**Returns**
510e41f4b71Sopenharmony_ci
511e41f4b71Sopenharmony_ciReturns the error code.
512e41f4b71Sopenharmony_ci
513e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
514e41f4b71Sopenharmony_ci
515e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
516e41f4b71Sopenharmony_ci
517e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
518e41f4b71Sopenharmony_ci
519e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
520e41f4b71Sopenharmony_ci
521e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_GET_DATAOBSMGRCLIENT** if the data change subscription service fails to be obtained.
522e41f4b71Sopenharmony_ci
523e41f4b71Sopenharmony_ci**See**
524e41f4b71Sopenharmony_ci
525e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
526e41f4b71Sopenharmony_ci
527e41f4b71Sopenharmony_ci[OH_PreferencesDataObserver](#oh_preferencesdataobserver)
528e41f4b71Sopenharmony_ci
529e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
530e41f4b71Sopenharmony_ci
531e41f4b71Sopenharmony_ci
532e41f4b71Sopenharmony_ci### OH_Preferences_SetBool()
533e41f4b71Sopenharmony_ci
534e41f4b71Sopenharmony_ci```
535e41f4b71Sopenharmony_ciint OH_Preferences_SetBool (OH_Preferences *preference, const char *key, bool value )
536e41f4b71Sopenharmony_ci```
537e41f4b71Sopenharmony_ci
538e41f4b71Sopenharmony_ci**Description**
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_ciSets a Boolean value based on the specified key in a **Preferences** instance.
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ci**Since**: 13
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_ci**Parameters**
545e41f4b71Sopenharmony_ci
546e41f4b71Sopenharmony_ci| Name| Description|
547e41f4b71Sopenharmony_ci| -------- | -------- |
548e41f4b71Sopenharmony_ci| preference | Pointer to the target [OH_Preferences](#oh_preferences) instance.|
549e41f4b71Sopenharmony_ci| key | Pointer to the key of the value to set.|
550e41f4b71Sopenharmony_ci| value | Boolean value to be set.|
551e41f4b71Sopenharmony_ci
552e41f4b71Sopenharmony_ci**Returns**
553e41f4b71Sopenharmony_ci
554e41f4b71Sopenharmony_ciReturns the error code.
555e41f4b71Sopenharmony_ci
556e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
557e41f4b71Sopenharmony_ci
558e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
559e41f4b71Sopenharmony_ci
560e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
561e41f4b71Sopenharmony_ci
562e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
563e41f4b71Sopenharmony_ci
564e41f4b71Sopenharmony_ci**See**
565e41f4b71Sopenharmony_ci
566e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
567e41f4b71Sopenharmony_ci
568e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
569e41f4b71Sopenharmony_ci
570e41f4b71Sopenharmony_ci
571e41f4b71Sopenharmony_ci### OH_Preferences_SetInt()
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_ci```
574e41f4b71Sopenharmony_ciint OH_Preferences_SetInt (OH_Preferences *preference, const char *key, int value )
575e41f4b71Sopenharmony_ci```
576e41f4b71Sopenharmony_ci
577e41f4b71Sopenharmony_ci**Description**
578e41f4b71Sopenharmony_ci
579e41f4b71Sopenharmony_ciSets an integer based on the specified key in a **Preferences** instance.
580e41f4b71Sopenharmony_ci
581e41f4b71Sopenharmony_ci**Since**: 13
582e41f4b71Sopenharmony_ci
583e41f4b71Sopenharmony_ci**Parameters**
584e41f4b71Sopenharmony_ci
585e41f4b71Sopenharmony_ci| Name| Description|
586e41f4b71Sopenharmony_ci| -------- | -------- |
587e41f4b71Sopenharmony_ci| preference | Pointer to the target [OH_Preferences](#oh_preferences) instance.|
588e41f4b71Sopenharmony_ci| key | Pointer to the key of the value to set.|
589e41f4b71Sopenharmony_ci| value | Integer value to be set.|
590e41f4b71Sopenharmony_ci
591e41f4b71Sopenharmony_ci**Returns**
592e41f4b71Sopenharmony_ci
593e41f4b71Sopenharmony_ciReturns the error code.
594e41f4b71Sopenharmony_ci
595e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
596e41f4b71Sopenharmony_ci
597e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
598e41f4b71Sopenharmony_ci
599e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
600e41f4b71Sopenharmony_ci
601e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
602e41f4b71Sopenharmony_ci
603e41f4b71Sopenharmony_ci**See**
604e41f4b71Sopenharmony_ci
605e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
606e41f4b71Sopenharmony_ci
607e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
608e41f4b71Sopenharmony_ci
609e41f4b71Sopenharmony_ci
610e41f4b71Sopenharmony_ci### OH_Preferences_SetString()
611e41f4b71Sopenharmony_ci
612e41f4b71Sopenharmony_ci```
613e41f4b71Sopenharmony_ciint OH_Preferences_SetString (OH_Preferences *preference, const char *key, const char *value )
614e41f4b71Sopenharmony_ci```
615e41f4b71Sopenharmony_ci
616e41f4b71Sopenharmony_ci**Description**
617e41f4b71Sopenharmony_ci
618e41f4b71Sopenharmony_ciSets a string based on the specified key in a **Preferences** instance.
619e41f4b71Sopenharmony_ci
620e41f4b71Sopenharmony_ci**Since**: 13
621e41f4b71Sopenharmony_ci
622e41f4b71Sopenharmony_ci**Parameters**
623e41f4b71Sopenharmony_ci
624e41f4b71Sopenharmony_ci| Name| Description|
625e41f4b71Sopenharmony_ci| -------- | -------- |
626e41f4b71Sopenharmony_ci| preference | Pointer to the target [OH_Preferences](#oh_preferences) instance.|
627e41f4b71Sopenharmony_ci| key | Pointer to the key of the value to set.|
628e41f4b71Sopenharmony_ci| value | Pointer to the string to set.|
629e41f4b71Sopenharmony_ci
630e41f4b71Sopenharmony_ci**Returns**
631e41f4b71Sopenharmony_ci
632e41f4b71Sopenharmony_ciReturns the error code.
633e41f4b71Sopenharmony_ci
634e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
635e41f4b71Sopenharmony_ci
636e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
637e41f4b71Sopenharmony_ci
638e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
639e41f4b71Sopenharmony_ci
640e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
641e41f4b71Sopenharmony_ci
642e41f4b71Sopenharmony_ci**See**
643e41f4b71Sopenharmony_ci
644e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
645e41f4b71Sopenharmony_ci
646e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
647e41f4b71Sopenharmony_ci
648e41f4b71Sopenharmony_ci
649e41f4b71Sopenharmony_ci### OH_Preferences_UnregisterDataObserver()
650e41f4b71Sopenharmony_ci
651e41f4b71Sopenharmony_ci```
652e41f4b71Sopenharmony_ciint OH_Preferences_UnregisterDataObserver (OH_Preferences *preference, void *context, OH_PreferencesDataObserver observer, const char *keys[], uint32_t keyCount )
653e41f4b71Sopenharmony_ci```
654e41f4b71Sopenharmony_ci
655e41f4b71Sopenharmony_ci**Description**
656e41f4b71Sopenharmony_ci
657e41f4b71Sopenharmony_ciUnsubscribes from data changes of the specified keys.
658e41f4b71Sopenharmony_ci
659e41f4b71Sopenharmony_ci**Since**: 13
660e41f4b71Sopenharmony_ci
661e41f4b71Sopenharmony_ci**Parameters**
662e41f4b71Sopenharmony_ci
663e41f4b71Sopenharmony_ci| Name| Description|
664e41f4b71Sopenharmony_ci| -------- | -------- |
665e41f4b71Sopenharmony_ci| preference | Pointer to the target [OH_Preferences](#oh_preferences) instance.|
666e41f4b71Sopenharmony_ci| context | Pointer to the application context.|
667e41f4b71Sopenharmony_ci| observer | [OH_PreferencesDataObserver](#oh_preferencesdataobserver) callback to unregister.|
668e41f4b71Sopenharmony_ci| keys | Pointer to the keys of the values whose changes are not observed.|
669e41f4b71Sopenharmony_ci| keyCount | Number of keys.|
670e41f4b71Sopenharmony_ci
671e41f4b71Sopenharmony_ci**Returns**
672e41f4b71Sopenharmony_ci
673e41f4b71Sopenharmony_ciReturns the error code.
674e41f4b71Sopenharmony_ci
675e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
676e41f4b71Sopenharmony_ci
677e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
678e41f4b71Sopenharmony_ci
679e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
680e41f4b71Sopenharmony_ci
681e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
682e41f4b71Sopenharmony_ci
683e41f4b71Sopenharmony_ci**See**
684e41f4b71Sopenharmony_ci
685e41f4b71Sopenharmony_ci[OH_Preferences](#oh_preferences)
686e41f4b71Sopenharmony_ci
687e41f4b71Sopenharmony_ci[OH_PreferencesDataObserver](#oh_preferencesdataobserver)
688e41f4b71Sopenharmony_ci
689e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
690e41f4b71Sopenharmony_ci
691e41f4b71Sopenharmony_ci
692e41f4b71Sopenharmony_ci### OH_PreferencesOption_Create()
693e41f4b71Sopenharmony_ci
694e41f4b71Sopenharmony_ci```
695e41f4b71Sopenharmony_ciOH_PreferencesOption* OH_PreferencesOption_Create (void )
696e41f4b71Sopenharmony_ci```
697e41f4b71Sopenharmony_ci
698e41f4b71Sopenharmony_ci**Description**
699e41f4b71Sopenharmony_ci
700e41f4b71Sopenharmony_ciCreates an [OH_PreferencesOption](#oh_preferencesoption) instance and a pointer to it. If this pointer is no longer required, use [OH_PreferencesOption_Destroy](#oh_preferencesoption_destroy) to destroy it. Otherwise, memory leaks may occur.
701e41f4b71Sopenharmony_ci
702e41f4b71Sopenharmony_ci**Since**: 13
703e41f4b71Sopenharmony_ci
704e41f4b71Sopenharmony_ci**Returns**
705e41f4b71Sopenharmony_ci
706e41f4b71Sopenharmony_ciReturns a pointer to the [OH_PreferencesOption](#oh_preferencesoption) instance created if the operation is successful; returns a null pointer otherwise.
707e41f4b71Sopenharmony_ci
708e41f4b71Sopenharmony_ci**See**
709e41f4b71Sopenharmony_ci
710e41f4b71Sopenharmony_ci[OH_PreferencesOption](#oh_preferencesoption)
711e41f4b71Sopenharmony_ci
712e41f4b71Sopenharmony_ci
713e41f4b71Sopenharmony_ci### OH_PreferencesOption_Destroy()
714e41f4b71Sopenharmony_ci
715e41f4b71Sopenharmony_ci```
716e41f4b71Sopenharmony_ciint OH_PreferencesOption_Destroy (OH_PreferencesOption *option)
717e41f4b71Sopenharmony_ci```
718e41f4b71Sopenharmony_ci
719e41f4b71Sopenharmony_ci**Description**
720e41f4b71Sopenharmony_ci
721e41f4b71Sopenharmony_ciDestroys an [OH_PreferencesOption](#oh_preferencesoption) instance.
722e41f4b71Sopenharmony_ci
723e41f4b71Sopenharmony_ci**Since**: 13
724e41f4b71Sopenharmony_ci
725e41f4b71Sopenharmony_ci**Parameters**
726e41f4b71Sopenharmony_ci
727e41f4b71Sopenharmony_ci| Name| Description|
728e41f4b71Sopenharmony_ci| -------- | -------- |
729e41f4b71Sopenharmony_ci| option | Pointer to the [OH_PreferencesOption](#oh_preferencesoption) instance to destroy.|
730e41f4b71Sopenharmony_ci
731e41f4b71Sopenharmony_ci**Returns**
732e41f4b71Sopenharmony_ci
733e41f4b71Sopenharmony_ciReturns the error code. Returns **PREFERENCES_OK** if the operation is successful. 
734e41f4b71Sopenharmony_ci
735e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
736e41f4b71Sopenharmony_ci
737e41f4b71Sopenharmony_ci**See**
738e41f4b71Sopenharmony_ci
739e41f4b71Sopenharmony_ci[OH_PreferencesOption](#oh_preferencesoption)
740e41f4b71Sopenharmony_ci
741e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
742e41f4b71Sopenharmony_ci
743e41f4b71Sopenharmony_ci
744e41f4b71Sopenharmony_ci### OH_PreferencesOption_SetBundleName()
745e41f4b71Sopenharmony_ci
746e41f4b71Sopenharmony_ci```
747e41f4b71Sopenharmony_ciint OH_PreferencesOption_SetBundleName (OH_PreferencesOption *option, const char *bundleName )
748e41f4b71Sopenharmony_ci```
749e41f4b71Sopenharmony_ci
750e41f4b71Sopenharmony_ci**Description**
751e41f4b71Sopenharmony_ci
752e41f4b71Sopenharmony_ciSets the bundle name for an [OH_PreferencesOption](#oh_preferencesoption) instance.
753e41f4b71Sopenharmony_ci
754e41f4b71Sopenharmony_ci**Since**: 13
755e41f4b71Sopenharmony_ci
756e41f4b71Sopenharmony_ci**Parameters**
757e41f4b71Sopenharmony_ci
758e41f4b71Sopenharmony_ci| Name| Description|
759e41f4b71Sopenharmony_ci| -------- | -------- |
760e41f4b71Sopenharmony_ci| option | Pointer to the target [OH_PreferencesOption](#oh_preferencesoption) instance.|
761e41f4b71Sopenharmony_ci| bundleName | Pointer to the bundle name to set.|
762e41f4b71Sopenharmony_ci
763e41f4b71Sopenharmony_ci**Returns**
764e41f4b71Sopenharmony_ci
765e41f4b71Sopenharmony_ciReturns the error code.
766e41f4b71Sopenharmony_ci
767e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
768e41f4b71Sopenharmony_ci
769e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
770e41f4b71Sopenharmony_ci
771e41f4b71Sopenharmony_ci**See**
772e41f4b71Sopenharmony_ci
773e41f4b71Sopenharmony_ci[OH_PreferencesOption](#oh_preferencesoption)
774e41f4b71Sopenharmony_ci
775e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
776e41f4b71Sopenharmony_ci
777e41f4b71Sopenharmony_ci
778e41f4b71Sopenharmony_ci### OH_PreferencesOption_SetDataGroupId()
779e41f4b71Sopenharmony_ci
780e41f4b71Sopenharmony_ci```
781e41f4b71Sopenharmony_ciint OH_PreferencesOption_SetDataGroupId (OH_PreferencesOption *option, const char *dataGroupId )
782e41f4b71Sopenharmony_ci```
783e41f4b71Sopenharmony_ci
784e41f4b71Sopenharmony_ci**Description**
785e41f4b71Sopenharmony_ci
786e41f4b71Sopenharmony_ciSets the application group ID for an [OH_PreferencesOption](#oh_preferencesoption) instance.
787e41f4b71Sopenharmony_ci
788e41f4b71Sopenharmony_ciAfter the application group ID is set, the **Preferences** instance will be created in the sandbox directory of the application group ID.
789e41f4b71Sopenharmony_ci
790e41f4b71Sopenharmony_ciThe application group ID must be obtained from AppGallery. This parameter is not supported currently.
791e41f4b71Sopenharmony_ci
792e41f4b71Sopenharmony_ciIf the application group ID is an empty string, the **Preferences** instance will be created in the sandbox directory of the current application.
793e41f4b71Sopenharmony_ci
794e41f4b71Sopenharmony_ci**Since**: 13
795e41f4b71Sopenharmony_ci
796e41f4b71Sopenharmony_ci**Parameters**
797e41f4b71Sopenharmony_ci
798e41f4b71Sopenharmony_ci| Name| Description|
799e41f4b71Sopenharmony_ci| -------- | -------- |
800e41f4b71Sopenharmony_ci| option | Pointer to the target [OH_PreferencesOption](#oh_preferencesoption) instance.|
801e41f4b71Sopenharmony_ci| dataGroupId | Pointer to the application group ID to set.|
802e41f4b71Sopenharmony_ci
803e41f4b71Sopenharmony_ci**Returns**
804e41f4b71Sopenharmony_ci
805e41f4b71Sopenharmony_ciReturns the error code.
806e41f4b71Sopenharmony_ci
807e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
808e41f4b71Sopenharmony_ci
809e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
810e41f4b71Sopenharmony_ci
811e41f4b71Sopenharmony_ci**See**
812e41f4b71Sopenharmony_ci
813e41f4b71Sopenharmony_ci[OH_PreferencesOption](#oh_preferencesoption)
814e41f4b71Sopenharmony_ci
815e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
816e41f4b71Sopenharmony_ci
817e41f4b71Sopenharmony_ci
818e41f4b71Sopenharmony_ci### OH_PreferencesOption_SetFileName()
819e41f4b71Sopenharmony_ci
820e41f4b71Sopenharmony_ci```
821e41f4b71Sopenharmony_ciint OH_PreferencesOption_SetFileName (OH_PreferencesOption *option, const char *fileName )
822e41f4b71Sopenharmony_ci```
823e41f4b71Sopenharmony_ci
824e41f4b71Sopenharmony_ci**Description**
825e41f4b71Sopenharmony_ci
826e41f4b71Sopenharmony_ciSets the file name for an [OH_PreferencesOption](#oh_preferencesoption) instance.
827e41f4b71Sopenharmony_ci
828e41f4b71Sopenharmony_ci**Since**: 13
829e41f4b71Sopenharmony_ci
830e41f4b71Sopenharmony_ci**Parameters**
831e41f4b71Sopenharmony_ci
832e41f4b71Sopenharmony_ci| Name| Description|
833e41f4b71Sopenharmony_ci| -------- | -------- |
834e41f4b71Sopenharmony_ci| option | Pointer to the target [OH_PreferencesOption](#oh_preferencesoption) instance.|
835e41f4b71Sopenharmony_ci| fileName | Pointer to the file name to set.|
836e41f4b71Sopenharmony_ci
837e41f4b71Sopenharmony_ci**Returns**
838e41f4b71Sopenharmony_ci
839e41f4b71Sopenharmony_ciReturns the error code.
840e41f4b71Sopenharmony_ci
841e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
842e41f4b71Sopenharmony_ci
843e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
844e41f4b71Sopenharmony_ci
845e41f4b71Sopenharmony_ci**See**
846e41f4b71Sopenharmony_ci
847e41f4b71Sopenharmony_ci[OH_PreferencesOption](#oh_preferencesoption)
848e41f4b71Sopenharmony_ci
849e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
850e41f4b71Sopenharmony_ci
851e41f4b71Sopenharmony_ci
852e41f4b71Sopenharmony_ci### OH_PreferencesPair_GetKey()
853e41f4b71Sopenharmony_ci
854e41f4b71Sopenharmony_ci```
855e41f4b71Sopenharmony_ciconst char* OH_PreferencesPair_GetKey (const OH_PreferencesPair *pairs, uint32_t index )
856e41f4b71Sopenharmony_ci```
857e41f4b71Sopenharmony_ci
858e41f4b71Sopenharmony_ci**Description**
859e41f4b71Sopenharmony_ci
860e41f4b71Sopenharmony_ciObtains the key based on the specified index from the KV data.
861e41f4b71Sopenharmony_ci
862e41f4b71Sopenharmony_ci**Since**: 13
863e41f4b71Sopenharmony_ci
864e41f4b71Sopenharmony_ci**Parameters**
865e41f4b71Sopenharmony_ci
866e41f4b71Sopenharmony_ci| Name| Description|
867e41f4b71Sopenharmony_ci| -------- | -------- |
868e41f4b71Sopenharmony_ci| pairs | Pointer to the target [OH_PreferencesPair](#oh_preferencespair).|
869e41f4b71Sopenharmony_ci| index | Index of the target [OH_PreferencesPair](#oh_preferencespair).|
870e41f4b71Sopenharmony_ci
871e41f4b71Sopenharmony_ci**Returns**
872e41f4b71Sopenharmony_ci
873e41f4b71Sopenharmony_ciReturns the pointer to the key obtained if the operation is successful. 
874e41f4b71Sopenharmony_ci
875e41f4b71Sopenharmony_ciReturns a null pointer if the operation fails or the input parameter is invalid.
876e41f4b71Sopenharmony_ci
877e41f4b71Sopenharmony_ci**See**
878e41f4b71Sopenharmony_ci
879e41f4b71Sopenharmony_ci[OH_PreferencesPair](#oh_preferencespair)
880e41f4b71Sopenharmony_ci
881e41f4b71Sopenharmony_ci
882e41f4b71Sopenharmony_ci### OH_PreferencesPair_GetPreferencesValue()
883e41f4b71Sopenharmony_ci
884e41f4b71Sopenharmony_ci```
885e41f4b71Sopenharmony_ciconst OH_PreferencesValue* OH_PreferencesPair_GetPreferencesValue (const OH_PreferencesPair *pairs, uint32_t index )
886e41f4b71Sopenharmony_ci```
887e41f4b71Sopenharmony_ci
888e41f4b71Sopenharmony_ci**Description**
889e41f4b71Sopenharmony_ci
890e41f4b71Sopenharmony_ciObtains the value based on the specified index from the KV pairs.
891e41f4b71Sopenharmony_ci
892e41f4b71Sopenharmony_ci**Since**: 13
893e41f4b71Sopenharmony_ci
894e41f4b71Sopenharmony_ci**Parameters**
895e41f4b71Sopenharmony_ci
896e41f4b71Sopenharmony_ci| Name| Description|
897e41f4b71Sopenharmony_ci| -------- | -------- |
898e41f4b71Sopenharmony_ci| pairs | Pointer to the target [OH_PreferencesPair](#oh_preferencespair).|
899e41f4b71Sopenharmony_ci| index | Index of the target [OH_PreferencesPair](#oh_preferencespair).|
900e41f4b71Sopenharmony_ci
901e41f4b71Sopenharmony_ci**Returns**
902e41f4b71Sopenharmony_ci
903e41f4b71Sopenharmony_ciReturns the pointer to the value obtained if the operation is successful. 
904e41f4b71Sopenharmony_ci
905e41f4b71Sopenharmony_ciReturns a null pointer if the operation fails or the input parameter is invalid.
906e41f4b71Sopenharmony_ci
907e41f4b71Sopenharmony_ci**See**
908e41f4b71Sopenharmony_ci
909e41f4b71Sopenharmony_ci[OH_PreferencesValue](#oh_preferencesvalue)
910e41f4b71Sopenharmony_ci
911e41f4b71Sopenharmony_ci
912e41f4b71Sopenharmony_ci### OH_PreferencesValue_GetBool()
913e41f4b71Sopenharmony_ci
914e41f4b71Sopenharmony_ci```
915e41f4b71Sopenharmony_ciint OH_PreferencesValue_GetBool (const OH_PreferencesValue *object, bool *value )
916e41f4b71Sopenharmony_ci```
917e41f4b71Sopenharmony_ci
918e41f4b71Sopenharmony_ci**Description**
919e41f4b71Sopenharmony_ci
920e41f4b71Sopenharmony_ciObtains a Boolean value from an [OH_PreferencesValue](#oh_preferencesvalue) instance.
921e41f4b71Sopenharmony_ci
922e41f4b71Sopenharmony_ci**Since**: 13
923e41f4b71Sopenharmony_ci
924e41f4b71Sopenharmony_ci**Parameters**
925e41f4b71Sopenharmony_ci
926e41f4b71Sopenharmony_ci| Name| Description|
927e41f4b71Sopenharmony_ci| -------- | -------- |
928e41f4b71Sopenharmony_ci| object | Pointer to the target [OH_PreferencesValue](#oh_preferencesvalue) instance.|
929e41f4b71Sopenharmony_ci| value | Pointer to the Boolean value obtained.|
930e41f4b71Sopenharmony_ci
931e41f4b71Sopenharmony_ci**Returns**
932e41f4b71Sopenharmony_ci
933e41f4b71Sopenharmony_ciReturns the error code.
934e41f4b71Sopenharmony_ci
935e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
936e41f4b71Sopenharmony_ci
937e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
938e41f4b71Sopenharmony_ci
939e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
940e41f4b71Sopenharmony_ci
941e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
942e41f4b71Sopenharmony_ci
943e41f4b71Sopenharmony_ci**See**
944e41f4b71Sopenharmony_ci
945e41f4b71Sopenharmony_ci[OH_PreferencesValue](#oh_preferencesvalue)
946e41f4b71Sopenharmony_ci
947e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
948e41f4b71Sopenharmony_ci
949e41f4b71Sopenharmony_ci
950e41f4b71Sopenharmony_ci### OH_PreferencesValue_GetInt()
951e41f4b71Sopenharmony_ci
952e41f4b71Sopenharmony_ci```
953e41f4b71Sopenharmony_ciint OH_PreferencesValue_GetInt (const OH_PreferencesValue* object, int* value )
954e41f4b71Sopenharmony_ci```
955e41f4b71Sopenharmony_ci
956e41f4b71Sopenharmony_ci**Description**
957e41f4b71Sopenharmony_ci
958e41f4b71Sopenharmony_ciObtains an integer from an [OH_PreferencesValue](#oh_preferencesvalue) instance.
959e41f4b71Sopenharmony_ci
960e41f4b71Sopenharmony_ci**Since**: 13
961e41f4b71Sopenharmony_ci
962e41f4b71Sopenharmony_ci**Parameters**
963e41f4b71Sopenharmony_ci
964e41f4b71Sopenharmony_ci| Name| Description|
965e41f4b71Sopenharmony_ci| -------- | -------- |
966e41f4b71Sopenharmony_ci| object | Pointer to the target [OH_PreferencesValue](#oh_preferencesvalue) instance.|
967e41f4b71Sopenharmony_ci| value | Pointer to the integer value obtained.|
968e41f4b71Sopenharmony_ci
969e41f4b71Sopenharmony_ci**Returns**
970e41f4b71Sopenharmony_ci
971e41f4b71Sopenharmony_ciReturns the error code.
972e41f4b71Sopenharmony_ci
973e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
974e41f4b71Sopenharmony_ci
975e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
976e41f4b71Sopenharmony_ci
977e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
978e41f4b71Sopenharmony_ci
979e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
980e41f4b71Sopenharmony_ci
981e41f4b71Sopenharmony_ci**See**
982e41f4b71Sopenharmony_ci
983e41f4b71Sopenharmony_ci[OH_PreferencesValue](#oh_preferencesvalue)
984e41f4b71Sopenharmony_ci
985e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
986e41f4b71Sopenharmony_ci
987e41f4b71Sopenharmony_ci
988e41f4b71Sopenharmony_ci### OH_PreferencesValue_GetString()
989e41f4b71Sopenharmony_ci
990e41f4b71Sopenharmony_ci```
991e41f4b71Sopenharmony_ciint OH_PreferencesValue_GetString (const OH_PreferencesValue *object, char **value, uint32_t *valueLen )
992e41f4b71Sopenharmony_ci```
993e41f4b71Sopenharmony_ci
994e41f4b71Sopenharmony_ci**Description**
995e41f4b71Sopenharmony_ci
996e41f4b71Sopenharmony_ciObtains a string from an [OH_PreferencesValue](#oh_preferencesvalue) instance.
997e41f4b71Sopenharmony_ci
998e41f4b71Sopenharmony_ci**Since**: 13
999e41f4b71Sopenharmony_ci
1000e41f4b71Sopenharmony_ci**Parameters**
1001e41f4b71Sopenharmony_ci
1002e41f4b71Sopenharmony_ci| Name| Description|
1003e41f4b71Sopenharmony_ci| -------- | -------- |
1004e41f4b71Sopenharmony_ci| object | Pointer to the target [OH_PreferencesValue](#oh_preferencesvalue) instance.|
1005e41f4b71Sopenharmony_ci| value | Double pointer to the string obtained. If the string is not required, you can use [OH_Preferences_FreeString](#oh_preferences_freestring) to free the string (release the memory occupied by the string).|
1006e41f4b71Sopenharmony_ci| valueLen | Pointer to the length of the string obtained.|
1007e41f4b71Sopenharmony_ci
1008e41f4b71Sopenharmony_ci**Returns**
1009e41f4b71Sopenharmony_ci
1010e41f4b71Sopenharmony_ciReturns the error code.
1011e41f4b71Sopenharmony_ci
1012e41f4b71Sopenharmony_ciReturns **PREFERENCES_OK** if the operation is successful.
1013e41f4b71Sopenharmony_ci
1014e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_INVALID_PARAM** if invalid parameters are detected.
1015e41f4b71Sopenharmony_ci
1016e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_STORAGE** if the storage is abnormal.
1017e41f4b71Sopenharmony_ci
1018e41f4b71Sopenharmony_ciReturns **PREFERENCES_ERROR_MALLOC** if memory allocation fails.
1019e41f4b71Sopenharmony_ci
1020e41f4b71Sopenharmony_ci**See**
1021e41f4b71Sopenharmony_ci
1022e41f4b71Sopenharmony_ci[OH_PreferencesValue](#oh_preferencesvalue)
1023e41f4b71Sopenharmony_ci
1024e41f4b71Sopenharmony_ci[OH_Preferences_ErrCode](#oh_preferences_errcode)
1025e41f4b71Sopenharmony_ci
1026e41f4b71Sopenharmony_ci
1027e41f4b71Sopenharmony_ci### OH_PreferencesValue_GetValueType()
1028e41f4b71Sopenharmony_ci
1029e41f4b71Sopenharmony_ci```
1030e41f4b71Sopenharmony_ciPreference_ValueType OH_PreferencesValue_GetValueType (const OH_PreferencesValue *object)
1031e41f4b71Sopenharmony_ci```
1032e41f4b71Sopenharmony_ci
1033e41f4b71Sopenharmony_ci**Description**
1034e41f4b71Sopenharmony_ci
1035e41f4b71Sopenharmony_ciObtains the data type of a **PreferencesValue** instance.
1036e41f4b71Sopenharmony_ci
1037e41f4b71Sopenharmony_ci**Since**: 13
1038e41f4b71Sopenharmony_ci
1039e41f4b71Sopenharmony_ci**Parameters**
1040e41f4b71Sopenharmony_ci
1041e41f4b71Sopenharmony_ci| Name| Description|
1042e41f4b71Sopenharmony_ci| -------- | -------- |
1043e41f4b71Sopenharmony_ci| object | Pointer to the target [OH_PreferencesValue](#oh_preferencesvalue) instance.|
1044e41f4b71Sopenharmony_ci
1045e41f4b71Sopenharmony_ci**Returns**
1046e41f4b71Sopenharmony_ci
1047e41f4b71Sopenharmony_ciReturns the obtained data type. If **PREFERENCE_TYPE_NULL** is returned, invalid parameter is passed in.
1048e41f4b71Sopenharmony_ci
1049e41f4b71Sopenharmony_ci**See**
1050e41f4b71Sopenharmony_ci
1051e41f4b71Sopenharmony_ci[OH_PreferencesValue](#oh_preferencesvalue)
1052