harmony 鸿蒙Preferences

2025-06-12 浏览 (1)

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

NameDescription
oh_preferences.hProvides APIs and structs for accessing the Preferences object.
oh_preferences_err_code.hDefines the error codes used in the Preferences module.
oh_preferences_option.hProvides APIs and structs for accessing the PreferencesOption object.
oh_preferences_value.hProvides APIs, enums, and structs for accessing the PreferencesValue object.

Types

NameDescription
typedef struct OH_Preferences OH_PreferencesDefines 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_ErrCodeDefines an enum for error codes.
typedef struct OH_PreferencesOption OH_PreferencesOptionDefines a struct for Preferences configuration.
typedef enum Preference_ValueType Preference_ValueTypeDefines an enum for types of PreferencesValue.
typedef struct OH_PreferencesPair OH_PreferencesPairDefines a struct for the Preferences data in KV format.
typedef struct OH_PreferencesValue OH_PreferencesValueDefines the struct for a PreferencesValue object.
typedef enum Preferences_StorageType Preferences_StorageTypeDefines an enum for preferences storage types.

Enums

NameDescription
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

NameDescription
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

NameDescription
contextPointer to the application context.
pairsPointer to the changed KV data.
countNumber of KV pairs changed.

See

OH_PreferencesPair

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 ValueDescription
PREFERENCES_STORAGE_XMLXML. 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_GSKVCLKV. 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 ValueDescription
PREFERENCES_OKThe operation is successful.
PREFERENCES_ERROR_INVALID_PARAMInvalid parameter.
PREFERENCES_ERROR_NOT_SUPPORTEDThe system capability is not supported.
PREFERENCES_ERROR_BASEBase error code.
PREFERENCES_ERROR_DELETE_FILEFailed to delete the file.
PREFERENCES_ERROR_STORAGEThe storage is abnormal.
PREFERENCES_ERROR_MALLOCFailed to allocate memory.
PREFERENCES_ERROR_KEY_NOT_FOUNDThe key does not exist.
PREFERENCES_ERROR_GET_DATAOBSMGRCLIENTFailed to obtain the data change subscription service.

Preference_ValueType

enum Preference_ValueType

Description

Enumerates the types of PreferencesValue.

Since: 13

Enumerated ValueDescription
PREFERENCE_TYPE_NULLNull.
PREFERENCE_TYPE_INTInteger.
PREFERENCE_TYPE_BOOLBoolean.
PREFERENCE_TYPE_STRINGString.
PREFERENCE_TYPE_BUTTEnd 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

NameDescription
typeStorage type to check.
isSupportedPointer 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

NameDescription
optionPointer to the configuration whose storage type is to set.
typeStorage 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_PreferencesOption.

OH_Preferences_Close()

int OH_Preferences_Close (OH_Preferences *preference)

Description

Closes a Preferences instance.

Since: 13

Parameters

NameDescription
preferencePointer 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

OH_Preferences_ErrCode

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

NameDescription
preferencePointer to the target OH_Preferences instance.
keyPointer 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

OH_Preferences_ErrCode

OH_Preferences_FreeString()

void OH_Preferences_FreeString (char *string)

Description

Releases a string.

Since: 13

Parameters

NameDescription
stringPointer to the string to release.

See

OH_Preferences

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

NameDescription
preferencePointer to the target OH_Preferences instance.
keyPointer to the key of the value to obtain.
valuePointer 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

OH_Preferences_ErrCode

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

NameDescription
preferencePointer to the target OH_Preferences instance.
keyPointer to the key of the value to obtain.
valuePointer 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

OH_Preferences_ErrCode

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

NameDescription
preferencePointer to the target OH_Preferences instance.
keyPointer to the key of the value to obtain.
valueDouble 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).
valueLenPointer 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

OH_Preferences_ErrCode

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

NameDescription
optionPointer to the OH_PreferencesOption instance.
errCodePointer 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

OH_PreferencesOption

OH_Preferences_ErrCode

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

NameDescription
preferencePointer to the target OH_Preferences instance.
contextPointer to the application context.
observerOH_PreferencesDataObserver callback to be invoked when the data changes.
keysPointer to the keys of the data to be observed.
keyCountNumber 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

OH_PreferencesDataObserver

OH_Preferences_ErrCode

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

NameDescription
preferencePointer to the target OH_Preferences instance.
keyPointer to the key of the value to set.
valueBoolean 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

OH_Preferences_ErrCode

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

NameDescription
preferencePointer to the target OH_Preferences instance.
keyPointer to the key of the value to set.
valueInteger 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

OH_Preferences_ErrCode

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

NameDescription
preferencePointer to the target OH_Preferences instance.
keyPointer to the key of the value to set.
valuePointer 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

OH_Preferences_ErrCode

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

NameDescription
preferencePointer to the target OH_Preferences instance.
contextPointer to the application context.
observerOH_PreferencesDataObserver callback to unregister.
keysPointer to the keys of the values whose changes are not observed.
keyCountNumber 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_Preferences

OH_PreferencesDataObserver

OH_Preferences_ErrCode

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

OH_PreferencesOption_Destroy()

int OH_PreferencesOption_Destroy (OH_PreferencesOption *option)

Description

Destroys an OH_PreferencesOption instance.

Since: 13

Parameters

NameDescription
optionPointer 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

OH_Preferences_ErrCode

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

NameDescription
optionPointer to the target OH_PreferencesOption instance.
bundleNamePointer 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

OH_Preferences_ErrCode

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

NameDescription
optionPointer to the target OH_PreferencesOption instance.
dataGroupIdPointer 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

OH_Preferences_ErrCode

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

NameDescription
optionPointer to the target OH_PreferencesOption instance.
fileNamePointer 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_PreferencesOption

OH_Preferences_ErrCode

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

NameDescription
pairsPointer to the target OH_PreferencesPair.
indexIndex 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

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

NameDescription
pairsPointer to the target OH_PreferencesPair.
indexIndex 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

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

NameDescription
objectPointer to the target OH_PreferencesValue instance.
valuePointer 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

OH_Preferences_ErrCode

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

NameDescription
objectPointer to the target OH_PreferencesValue instance.
valuePointer 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

OH_Preferences_ErrCode

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

NameDescription
objectPointer to the target OH_PreferencesValue instance.
valueDouble 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).
valueLenPointer 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

OH_Preferences_ErrCode

OH_PreferencesValue_GetValueType()

Preference_ValueType OH_PreferencesValue_GetValueType (const OH_PreferencesValue *object)

Description

Obtains the data type of a PreferencesValue instance.

Since: 13

Parameters

NameDescription
objectPointer to the target OH_PreferencesValue instance.

Returns

Returns the obtained data type. If PREFERENCE_TYPE_NULL is returned, invalid parameter is passed in.

See

OH_PreferencesValue

你可能感兴趣的鸿蒙文章

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 鸿蒙_r_d_b

harmony 鸿蒙Rdb_ChangeInfo

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/zzga9M