1e41f4b71Sopenharmony_ci# oh_preferences.h 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Overview 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciProvides APIs and structs for accessing the **Preferences** object. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci**File to include**: <database/preferences/oh_preferences.h> 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci**Library**: libohpreferences.so 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci**System capability**: SystemCapability.DistributedDataManager.Preferences.Core 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci**Since**: 13 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ciRelated module: [Preferences](_preferences.md) 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## Summary 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci### Types 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci| Name| Description| 25e41f4b71Sopenharmony_ci| -------- | -------- | 26e41f4b71Sopenharmony_ci| typedef struct [OH_Preferences](_preferences.md#oh_preferences) [OH_Preferences](_preferences.md#oh_preferences) | Defines a **Preferences** object.| 27e41f4b71Sopenharmony_ci| typedef void(\* [OH_PreferencesDataObserver](_preferences.md#oh_preferencesdataobserver)) (void \*context, const [OH_PreferencesPair](_preferences.md#oh_preferencespair) \*pairs, uint32_t count) | Defines the callback to be invoked when data changes.| 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci### Functions 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci| Name| Description| 33e41f4b71Sopenharmony_ci| -------- | -------- | 34e41f4b71Sopenharmony_ci| [OH_Preferences](_preferences.md#oh_preferences) \* [OH_Preferences_Open](_preferences.md#oh_preferences_open) ([OH_PreferencesOption](_preferences.md#oh_preferencesoption) \*option, int \*errCode) | Opens a **Preferences** instance and creates a pointer to it. If this pointer is no longer required, use [OH_Preferences_Close](_preferences.md#oh_preferences_close) to close the instance.| 35e41f4b71Sopenharmony_ci| int [OH_Preferences_Close](_preferences.md#oh_preferences_close) ([OH_Preferences](_preferences.md#oh_preferences) \*preference) | Closes a **Preferences** instance.| 36e41f4b71Sopenharmony_ci| int [OH_Preferences_GetInt](_preferences.md#oh_preferences_getint) ([OH_Preferences](_preferences.md#oh_preferences) \*preference, const char \*key, int \*value) | Obtains an integer corresponding to the specified key in a **Preferences** instance.| 37e41f4b71Sopenharmony_ci| int [OH_Preferences_GetBool](_preferences.md#oh_preferences_getbool) ([OH_Preferences](_preferences.md#oh_preferences) \*preference, const char \*key, bool \*value) | Obtains a Boolean value corresponding to the specified key in a **Preferences** instance.| 38e41f4b71Sopenharmony_ci| int [OH_Preferences_GetString](_preferences.md#oh_preferences_getstring) ([OH_Preferences](_preferences.md#oh_preferences) \*preference, const char \*key, char \*\*value, uint32_t \*valueLen) | Obtains a string corresponding to the specified key in a **Preferences** instance.| 39e41f4b71Sopenharmony_ci| void [OH_Preferences_FreeString](_preferences.md#oh_preferences_freestring) (char \*string) | Releases a string.| 40e41f4b71Sopenharmony_ci| int [OH_Preferences_SetInt](_preferences.md#oh_preferences_setint) ([OH_Preferences](_preferences.md#oh_preferences) \*preference, const char \*key, int value) | Sets an integer value based on the specified key in a **Preferences** instance.| 41e41f4b71Sopenharmony_ci| int [OH_Preferences_SetBool](_preferences.md#oh_preferences_setbool) ([OH_Preferences](_preferences.md#oh_preferences) \*preference, const char \*key, bool value) | Sets a Boolean value based on the specified key in a **Preferences** instance.| 42e41f4b71Sopenharmony_ci| int [OH_Preferences_SetString](_preferences.md#oh_preferences_setstring) ([OH_Preferences](_preferences.md#oh_preferences) \*preference, const char \*key, const char \*value) | Sets a string based on the specified key in a **Preferences** instance.| 43e41f4b71Sopenharmony_ci| int [OH_Preferences_Delete](_preferences.md#oh_preferences_delete) ([OH_Preferences](_preferences.md#oh_preferences) \*preference, const char \*key) | Deletes a KV pair of the specified key from a **Preferences** object.| 44e41f4b71Sopenharmony_ci| int [OH_Preferences_RegisterDataObserver](_preferences.md#oh_preferences_registerdataobserver) ([OH_Preferences](_preferences.md#oh_preferences) \*preference, void \*context, [OH_PreferencesDataObserver](_preferences.md#oh_preferencesdataobserver) observer, const char \*keys[], uint32_t keyCount) | Subscribes to data changes of the specified key. If the value of the specified key changes, a callback will be invoked after **OH_Preferences_Close ()** is called.| 45e41f4b71Sopenharmony_ci| int [OH_Preferences_UnregisterDataObserver](_preferences.md#oh_preferences_unregisterdataobserver) ([OH_Preferences](_preferences.md#oh_preferences) \*preference, void \*context, [OH_PreferencesDataObserver](_preferences.md#oh_preferencesdataobserver) observer, const char \*keys[], uint32_t keyCount) | Unsubscribes from data changes of the specified key.| 46