harmony 鸿蒙Preferences
Preferences
Overview
The Preferences module provides APIs for key-value (KV) data processing, including querying, modifying, and persisting KV data.
System capability: SystemCapability.DistributedDataManager.Preferences.Core
Since: 13
Summary
Files
Name | Description |
---|---|
oh_preferences.h | Provides APIs and structs for accessing the Preferences object. |
oh_preferences_err_code.h | Defines the error codes used in the Preferences module. |
oh_preferences_option.h | Provides APIs and structs for accessing the PreferencesOption object. |
oh_preferences_value.h | Provides APIs, enums, and structs for accessing the PreferencesValue object. |
Types
Name | Description |
---|---|
typedef struct OH_Preferences OH_Preferences | Defines a struct for a Preferences object. |
typedef void(* OH_PreferencesDataObserver) (void *context, const OH_PreferencesPair *pairs, uint32_t count) | Defines a struct for the callback for data changes. |
typedef enum OH_Preferences_ErrCode OH_Preferences_ErrCode | Defines an enum for error codes. |
typedef struct OH_PreferencesOption OH_PreferencesOption | Defines a struct for Preferences configuration. |
typedef enum Preference_ValueType Preference_ValueType | Defines an enum for types of PreferencesValue. |
typedef struct OH_PreferencesPair OH_PreferencesPair | Defines a struct for the Preferences data in KV format. |
typedef struct OH_PreferencesValue OH_PreferencesValue | Defines the struct for a PreferencesValue object. |
typedef enum Preferences_StorageType Preferences_StorageType | Defines an enum for preferences storage types. |
Enums
Name | Description |
---|---|
OH_Preferences_ErrCode { PREFERENCES_OK = 0, PREFERENCES_ERROR_INVALID_PARAM = 401, PREFERENCES_ERROR_NOT_SUPPORTED = 801, PREFERENCES_ERROR_BASE = 15500000, PREFERENCES_ERROR_DELETE_FILE = 15500010, PREFERENCES_ERROR_STORAGE = 15500011, PREFERENCES_ERROR_MALLOC = 15500012, PREFERENCES_ERROR_KEY_NOT_FOUND = 15500013, PREFERENCES_ERROR_GET_DATAOBSMGRCLIENT = 15500019 } |
Enumerates the error codes. |
Preference_ValueType { PREFERENCE_TYPE_NULL = 0, PREFERENCE_TYPE_INT, PREFERENCE_TYPE_BOOL, PREFERENCE_TYPE_STRING, PREFERENCE_TYPE_BUTT } |
Enumerates the types of PreferencesValue. |
Preferences_StorageType { PREFERENCES_STORAGE_XML = 0, PREFERENCES_STORAGE_GSKV } | Enumerates the preferences storage types. |
Functions
Name | Description |
---|---|
int OH_PreferencesOption_SetStorageType (OH_PreferencesOption *option, Preferences_StorageType type) | Sets the storage type for a preferences instance. |
int OH_Preferences_IsStorageTypeSupported (Preferences_StorageType type, bool *isSupported) | Checks whether the specified storage type is supported. |
OH_Preferences * OH_Preferences_Open (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 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 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 the KV data corresponding to the specified key from a Preferences instance. |
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 keys. 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 keys. |
OH_PreferencesOption * OH_PreferencesOption_Create (void) | Creates an OH_PreferencesOption instance and a pointer to it. If this pointer is no longer required, use OH_PreferencesOption_Destroy to destroy it. Otherwise, memory leaks may occur. |
int OH_PreferencesOption_SetFileName (OH_PreferencesOption *option, const char *fileName) | Sets the file name for an OH_PreferencesOption instance. |
int OH_PreferencesOption_SetBundleName (OH_PreferencesOption *option, const char *bundleName) | Sets the bundle name for an OH_PreferencesOption instance. |
int OH_PreferencesOption_SetDataGroupId (OH_PreferencesOption *option, const char *dataGroupId) | Sets the application group ID for an OH_PreferencesOption instance. |
int OH_PreferencesOption_Destroy (OH_PreferencesOption *option) | Destroys an OH_PreferencesOption instance. |
const char * OH_PreferencesPair_GetKey (const OH_PreferencesPair *pairs, uint32_t index) | Obtains the key based on the specified index from the KV data. |
const OH_PreferencesValue * OH_PreferencesPair_GetPreferencesValue (const OH_PreferencesPair *pairs, uint32_t index) | Obtains the value based on the specified index from the KV pairs. |
Preference_ValueType OH_PreferencesValue_GetValueType (const OH_PreferencesValue *object) | Obtains the data type of a PreferencesValue instance. |
int OH_PreferencesValue_GetInt (const OH_PreferencesValue *object, int *value) | Obtains an integer value from an OH_PreferencesValue instance. |
int OH_PreferencesValue_GetBool (const OH_PreferencesValue *object, bool *value) | Obtains a Boolean value from an OH_PreferencesValue instance. |
int OH_PreferencesValue_GetString (const OH_PreferencesValue *object, char **value, uint32_t *valueLen) | Obtains a string from an OH_PreferencesValue instance. |
Type Description
Preferences_StorageType
typedef enum Preferences_StorageType Preferences_StorageType
Description
Defines an enum for preferences storage types.
Since: 18
OH_Preferences
typedef struct OH_Preferences OH_Preferences
Description
Represents a Preferences object.
Since: 13
OH_Preferences_ErrCode
typedef enum OH_Preferences_ErrCode OH_Preferences_ErrCode
Description
Defines an enum for error codes.
Since: 13
OH_PreferencesDataObserver
typedef void(*OH_PreferencesDataObserver) (void *context, const OH_PreferencesPair *pairs, uint32_t count)
Description
Defines a struct for the callback used to return data changes.
Since: 13
Parameters
Name | Description |
---|---|
context | Pointer to the application context. |
pairs | Pointer to the changed KV data. |
count | Number of KV pairs changed. |
See
OH_PreferencesOption
typedef struct OH_PreferencesOption OH_PreferencesOption
Description
Defines a struct for Preferences configuration.
Since: 13
OH_PreferencesPair
typedef struct OH_PreferencesPair OH_PreferencesPair
Description
Defines a struct for the Preferences data in KV format.
Since: 13
OH_PreferencesValue
typedef struct OH_PreferencesValue OH_PreferencesValue
Description
Defines the struct for a PreferencesValue object.
Since: 13
Preference_ValueType
typedef enum Preference_ValueType Preference_ValueType
Description
Defines an enum for types of PreferencesValue.
Since: 13
Enum Description
Preferences_StorageType
enum Preferences_StorageType
Description
Enumerates the preferences storage types.
Since: 18
Enumerated Value | Description |
---|---|
PREFERENCES_STORAGE_XML | XML. In this type is used, data operations are performed in the memory and data is persisted after OH_Preferences_Close is called. This type does not multi-processes operations. |
PREFERENCES_STORAGE_GSKV | CLKV. If this type is used, data operations are flushed on a real-time basis. This type supports multi-process operations. |
OH_Preferences_ErrCode
enum OH_Preferences_ErrCode
Description
Enumerates the error codes.
Since: 13
Enumerated Value | Description |
---|---|
PREFERENCES_OK | The operation is successful. |
PREFERENCES_ERROR_INVALID_PARAM | Invalid parameter. |
PREFERENCES_ERROR_NOT_SUPPORTED | The system capability is not supported. |
PREFERENCES_ERROR_BASE | Base error code. |
PREFERENCES_ERROR_DELETE_FILE | Failed to delete the file. |
PREFERENCES_ERROR_STORAGE | The storage is abnormal. |
PREFERENCES_ERROR_MALLOC | Failed to allocate memory. |
PREFERENCES_ERROR_KEY_NOT_FOUND | The key does not exist. |
PREFERENCES_ERROR_GET_DATAOBSMGRCLIENT | Failed to obtain the data change subscription service. |
Preference_ValueType
enum Preference_ValueType
Description
Enumerates the types of PreferencesValue.
Since: 13
Enumerated Value | Description |
---|---|
PREFERENCE_TYPE_NULL | Null. |
PREFERENCE_TYPE_INT | Integer. |
PREFERENCE_TYPE_BOOL | Boolean. |
PREFERENCE_TYPE_STRING | String. |
PREFERENCE_TYPE_BUTT | End type. |
Function Description
OH_Preferences_IsStorageTypeSupported()
int OH_Preferences_IsStorageTypeSupported (Preferences_StorageType type, bool *isSupported )
Description
Checks whether the specified storage type is supported.
Since: 18
Parameters
Name | Description |
---|---|
type | Storage type to check. |
isSupported | Pointer to the check result. The value true means the storage type is supported; the value false means the opposite. |
Returns
Returns the operation status code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
OH_PreferencesOption_SetStorageType()
int OH_PreferencesOption_SetStorageType (OH_PreferencesOption *option, Preferences_StorageType type )
Description
Sets the storage type for a preferences instance.
Since: 18
Parameters
Name | Description |
---|---|
option | Pointer to the configuration whose storage type is to set. |
type | Storage type to set. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
See
OH_Preferences_Close()
int OH_Preferences_Close (OH_Preferences *preference)
Description
Closes a Preferences instance.
Since: 13
Parameters
Name | Description |
---|---|
preference | Pointer to the OH_Preferences instance to close. |
Returns
Returns OH_Preferences_ErrCode.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
See
OH_Preferences_Delete()
int OH_Preferences_Delete (OH_Preferences *preference, const char *key )
Description
Deletes the KV data corresponding to the specified key from a Preferences instance.
Since: 13
Parameters
Name | Description |
---|---|
preference | Pointer to the target OH_Preferences instance. |
key | Pointer to the key of the KV pair to delete. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
See
OH_Preferences_FreeString()
void OH_Preferences_FreeString (char *string)
Description
Releases a string.
Since: 13
Parameters
Name | Description |
---|---|
string | Pointer to the string to release. |
See
OH_Preferences_GetBool()
int OH_Preferences_GetBool (OH_Preferences *preference, const char *key, bool *value )
Description
Obtains a Boolean value corresponding to the specified key in a Preferences instance.
Since: 13
Parameters
Name | Description |
---|---|
preference | Pointer to the target OH_Preferences instance. |
key | Pointer to the key of the value to obtain. |
value | Pointer to the Boolean value obtained. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
PREFERENCES_ERROR_KEY_NOT_FOUND indicates that the specified key does not exist.
See
OH_Preferences_GetInt()
int OH_Preferences_GetInt (OH_Preferences *preference, const char *key, int *value )
Description
Obtains an integer corresponding to the specified key in a Preferences instance.
Since: 13
Parameters
Name | Description |
---|---|
preference | Pointer to the target OH_Preferences instance. |
key | Pointer to the key of the value to obtain. |
value | Pointer to the integer value obtained. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
PREFERENCES_ERROR_KEY_NOT_FOUND indicates that the specified key does not exist.
See
OH_Preferences_GetString()
int OH_Preferences_GetString (OH_Preferences *preference, const char *key, char **value, uint32_t *valueLen )
Description
Obtains a string corresponding to the specified key in a Preferences instance.
Since: 13
Parameters
Name | Description |
---|---|
preference | Pointer to the target OH_Preferences instance. |
key | Pointer to the key of the value to obtain. |
value | Double pointer to the string obtained. If the string is not required, you can use OH_Preferences_FreeString to free the string (release the memory occupied by the string). |
valueLen | Pointer to the length of the string obtained. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
PREFERENCES_ERROR_KEY_NOT_FOUND indicates that the specified key does not exist.
See
OH_Preferences_Open()
OH_Preferences* OH_Preferences_Open (OH_PreferencesOption *option, int *errCode )
Description
Opens a Preferences instance and creates a pointer to it. If the pointer is no longer required, use OH_Preferences_Close to close the instance.
Since: 13
Parameters
Name | Description |
---|---|
option | Pointer to the OH_PreferencesOption instance. |
errCode | Pointer to the error code returned. For details, see OH_Preferences_ErrCode. |
Returns
Returns the OH_Preferences instance opened if the operation is successful; returns a null pointer otherwise.
See
OH_Preferences_RegisterDataObserver()
int OH_Preferences_RegisterDataObserver (OH_Preferences *preference, void *context, OH_PreferencesDataObserver observer, const char *keys[], uint32_t keyCount )
Description
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.
Since: 13
Parameters
Name | Description |
---|---|
preference | Pointer to the target OH_Preferences instance. |
context | Pointer to the application context. |
observer | OH_PreferencesDataObserver callback to be invoked when the data changes. |
keys | Pointer to the keys of the data to be observed. |
keyCount | Number of keys observed. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
PREFERENCES_ERROR_GET_DATAOBSMGRCLIENT indicates a failure in obtaining the data change subscription service.
See
OH_Preferences_SetBool()
int OH_Preferences_SetBool (OH_Preferences *preference, const char *key, bool value )
Description
Sets a Boolean value based on the specified key in a Preferences instance.
Since: 13
Parameters
Name | Description |
---|---|
preference | Pointer to the target OH_Preferences instance. |
key | Pointer to the key of the value to set. |
value | Boolean value to be set. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
See
OH_Preferences_SetInt()
int OH_Preferences_SetInt (OH_Preferences *preference, const char *key, int value )
Description
Sets an integer based on the specified key in a Preferences instance.
Since: 13
Parameters
Name | Description |
---|---|
preference | Pointer to the target OH_Preferences instance. |
key | Pointer to the key of the value to set. |
value | Integer value to be set. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
See
OH_Preferences_SetString()
int OH_Preferences_SetString (OH_Preferences *preference, const char *key, const char *value )
Description
Sets a string based on the specified key in a Preferences instance.
Since: 13
Parameters
Name | Description |
---|---|
preference | Pointer to the target OH_Preferences instance. |
key | Pointer to the key of the value to set. |
value | Pointer to the string to set. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
See
OH_Preferences_UnregisterDataObserver()
int OH_Preferences_UnregisterDataObserver (OH_Preferences *preference, void *context, OH_PreferencesDataObserver observer, const char *keys[], uint32_t keyCount )
Description
Unsubscribes from data changes of the specified keys.
Since: 13
Parameters
Name | Description |
---|---|
preference | Pointer to the target OH_Preferences instance. |
context | Pointer to the application context. |
observer | OH_PreferencesDataObserver callback to unregister. |
keys | Pointer to the keys of the values whose changes are not observed. |
keyCount | Number of keys. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
See
OH_PreferencesOption_Create()
OH_PreferencesOption* OH_PreferencesOption_Create (void )
Description
Creates an OH_PreferencesOption instance and a pointer to it.
If this pointer is no longer required, use OH_PreferencesOption_Destroy to destroy it. Otherwise, memory leaks may occur.
Since: 13
Returns
Returns a pointer to the OH_PreferencesOption instance created if the operation is successful; returns a null pointer otherwise.
See
OH_PreferencesOption_Destroy()
int OH_PreferencesOption_Destroy (OH_PreferencesOption *option)
Description
Destroys an OH_PreferencesOption instance.
Since: 13
Parameters
Name | Description |
---|---|
option | Pointer to the OH_PreferencesOption instance to destroy. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
See
OH_PreferencesOption_SetBundleName()
int OH_PreferencesOption_SetBundleName (OH_PreferencesOption *option, const char *bundleName )
Description
Sets the bundle name for an OH_PreferencesOption instance.
Since: 13
Parameters
Name | Description |
---|---|
option | Pointer to the target OH_PreferencesOption instance. |
bundleName | Pointer to the bundle name to set. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
See
OH_PreferencesOption_SetDataGroupId()
int OH_PreferencesOption_SetDataGroupId (OH_PreferencesOption *option, const char *dataGroupId )
Description
Sets the application group ID for an OH_PreferencesOption instance.
After the application group ID is set, the Preferences instance will be created in the sandbox directory of the application group ID.
The application group ID must be obtained from AppGallery. This parameter is not supported currently.
If the application group ID is an empty string, the Preferences instance will be created in the sandbox directory of the current application.
Since: 13
Parameters
Name | Description |
---|---|
option | Pointer to the target OH_PreferencesOption instance. |
dataGroupId | Pointer to the application group ID to set. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
See
OH_PreferencesOption_SetFileName()
int OH_PreferencesOption_SetFileName (OH_PreferencesOption *option, const char *fileName )
Description
Sets the file name for an OH_PreferencesOption instance.
Since: 13
Parameters
Name | Description |
---|---|
option | Pointer to the target OH_PreferencesOption instance. |
fileName | Pointer to the file name to set. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
See
OH_PreferencesPair_GetKey()
const char* OH_PreferencesPair_GetKey (const OH_PreferencesPair *pairs, uint32_t index )
Description
Obtains the key based on the specified index from the KV data.
Since: 13
Parameters
Name | Description |
---|---|
pairs | Pointer to the target OH_PreferencesPair. |
index | Index of the target OH_PreferencesPair. |
Returns
Returns the pointer to the key obtained if the operation is successful.
Returns a null pointer if the operation fails or the input parameter is invalid.
See
OH_PreferencesPair_GetPreferencesValue()
const OH_PreferencesValue* OH_PreferencesPair_GetPreferencesValue (const OH_PreferencesPair *pairs, uint32_t index )
Description
Obtains the value based on the specified index from the KV pairs.
Since: 13
Parameters
Name | Description |
---|---|
pairs | Pointer to the target OH_PreferencesPair. |
index | Index of the target OH_PreferencesPair. |
Returns
Returns the pointer to the value obtained if the operation is successful.
Returns a null pointer if the operation fails or the input parameter is invalid.
See
OH_PreferencesValue_GetBool()
int OH_PreferencesValue_GetBool (const OH_PreferencesValue *object, bool *value )
Description
Obtains a Boolean value from an OH_PreferencesValue instance.
Since: 13
Parameters
Name | Description |
---|---|
object | Pointer to the target OH_PreferencesValue instance. |
value | Pointer to the Boolean value obtained. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
See
OH_PreferencesValue_GetInt()
int OH_PreferencesValue_GetInt (const OH_PreferencesValue* object, int* value )
Description
Obtains an integer from an OH_PreferencesValue instance.
Since: 13
Parameters
Name | Description |
---|---|
object | Pointer to the target OH_PreferencesValue instance. |
value | Pointer to the integer value obtained. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
See
OH_PreferencesValue_GetString()
int OH_PreferencesValue_GetString (const OH_PreferencesValue *object, char **value, uint32_t *valueLen )
Description
Obtains a string from an OH_PreferencesValue instance.
Since: 13
Parameters
Name | Description |
---|---|
object | Pointer to the target OH_PreferencesValue instance. |
value | Double pointer to the string obtained. If the string is not required, you can use OH_Preferences_FreeString to free the string (release the memory occupied by the string). |
valueLen | Pointer to the length of the string obtained. |
Returns
Returns the error code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.
PREFERENCES_ERROR_STORAGE indicates the storage is abnormal.
PREFERENCES_ERROR_MALLOC indicates a failure in memory allocation.
See
OH_PreferencesValue_GetValueType()
Preference_ValueType OH_PreferencesValue_GetValueType (const OH_PreferencesValue *object)
Description
Obtains the data type of a PreferencesValue instance.
Since: 13
Parameters
Name | Description |
---|---|
object | Pointer to the target OH_PreferencesValue instance. |
Returns
Returns the obtained data type. If PREFERENCE_TYPE_NULL is returned, invalid parameter is passed in.
See
你可能感兴趣的鸿蒙文章
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦