harmony 鸿蒙oh_preferences.h

  • 2025-06-12
  • 浏览 (8)

oh_preferences.h

Overview

Provides APIs and structs for accessing the Preferences object.

File to include: <database/preferences/oh_preferences.h>

Library: libohpreferences.so

System capability: SystemCapability.DistributedDataManager.Preferences.Core

Since: 13

Related module: Preferences

Summary

Types

Name Description
typedef struct OH_Preferences OH_Preferences Defines a Preferences object.
typedef void(* OH_PreferencesDataObserver) (void *context, const OH_PreferencesPair *pairs, uint32_t count) Defines the callback to be invoked when data changes.

Functions

Name Description
OH_Preferences * OH_Preferences_Open (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 to close the instance.
int OH_Preferences_Close (OH_Preferences *preference) Closes a Preferences instance.
int OH_Preferences_GetInt (OH_Preferences *preference, const char *key, int *value) Obtains an integer corresponding to the specified key in a Preferences instance.
int OH_Preferences_GetBool (OH_Preferences *preference, const char *key, bool *value) Obtains a Boolean value corresponding to the specified key in a Preferences instance.
int OH_Preferences_GetString (OH_Preferences *preference, const char *key, char **value, uint32_t *valueLen) Obtains a string corresponding to the specified key in a Preferences instance.
void OH_Preferences_FreeString (char *string) Releases a string.
int OH_Preferences_SetInt (OH_Preferences *preference, const char *key, int value) Sets an integer value based on the specified key in a Preferences instance.
int OH_Preferences_SetBool (OH_Preferences *preference, const char *key, bool value) Sets a Boolean value based on the specified key in a Preferences instance.
int OH_Preferences_SetString (OH_Preferences *preference, const char *key, const char *value) Sets a string based on the specified key in a Preferences instance.
int OH_Preferences_Delete (OH_Preferences *preference, const char *key) Deletes a KV pair of the specified key from a Preferences object.
int OH_Preferences_RegisterDataObserver (OH_Preferences *preference, void *context, 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.
int OH_Preferences_UnregisterDataObserver (OH_Preferences *preference, void *context, OH_PreferencesDataObserver observer, const char *keys[], uint32_t keyCount) Unsubscribes from data changes of the specified key.
int OH_Preferences_IsStorageTypeSupported (Preferences_StorageType type, bool *isSupported) Checks whether the specified storage type is supported.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkData (ArkData Management)

harmony 鸿蒙Data

harmony 鸿蒙OH_Cursor

harmony 鸿蒙OH_Predicates

harmony 鸿蒙OH_Rdb_Config

harmony 鸿蒙OH_Rdb_Store

harmony 鸿蒙OH_VBucket

harmony 鸿蒙OH_VObject

harmony 鸿蒙Preferences

harmony 鸿蒙_r_d_b

0  赞