openharmony 鸿蒙 capi-oh-preferences-option-h

2026-08-25 浏览 (1)

oh_preferences_option.h

Overview

Provides APIs and structs for accessing the PreferencesOption object.

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

Library: libohpreferences.so

System capability: SystemCapability.DistributedDataManager.Preferences.Core

Since: 13

Related module: Preferences

Summary

Structs

Nametypedef KeywordDescription
OH_PreferencesOptionOH_PreferencesOptionDefines a struct for Preferences configuration.

Enums

Nametypedef KeywordDescription
Preferences_StorageTypePreferences_StorageTypeEnumerates the preferences storage types.

Functions

NameDescription
OH_PreferencesOption *OH_PreferencesOption_Create(void)Creates a 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.
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.
int OH_PreferencesOption_SetStorageType(OH_PreferencesOption *option, Preferences_StorageType type)Sets the storage type for a Preferences instance.
int OH_PreferencesOption_Destroy(OH_PreferencesOption *option)Destroys an OH_PreferencesOption instance.

Enum Description

Preferences_StorageType

enum Preferences_StorageType

Description

Enumerates the preferences storage types.

Since: 18

EnumDescription
PREFERENCES_STORAGE_XML = 0XML. 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.

Function Description

OH_PreferencesOption_Create()

OH_PreferencesOption *OH_PreferencesOption_Create(void)

Description

Creates a 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

TypeDescription
OH_PreferencesOptionReturns a pointer to the OH_PreferencesOption instance created if the operation is successful; returns a null pointer otherwise.

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
OH_PreferencesOption *optionPointer to the OH_PreferencesOption instance.
const char *fileNamePointer to the file name to set.

Returns

TypeDescription
intError code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.

See

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
OH_PreferencesOption *optionPointer to the OH_PreferencesOption instance.
const char *bundleNamePointer to the bundle name to set.

Returns

TypeDescription
intError code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.

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
OH_PreferencesOption *optionPointer to the OH_PreferencesOption instance.
const char *dataGroupIdPointer to the application group ID to set.

Returns

TypeDescription
intError 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
OH_PreferencesOption *optionPointer to the configuration whose storage type is to set.
Preferences_StorageType typeStorage type to set.

Returns

TypeDescription
intError code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.

OH_PreferencesOption_Destroy()

int OH_PreferencesOption_Destroy(OH_PreferencesOption *option)

Description

Destroys an OH_PreferencesOption instance.

Since: 13

Parameters

NameDescription
OH_PreferencesOption *optionPointer to the OH_PreferencesOption instance.

Returns

TypeDescription
intOperation status code.
PREFERENCES_OK indicates the operation is successful.
PREFERENCES_ERROR_INVALID_PARAM indicates invalid parameters are specified.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 js-apis-distributedKVStore-sys

openharmony 鸿蒙 capi-oh-preferences-h

openharmony 鸿蒙 capi-udmf-oh-udshyperlink

openharmony 鸿蒙 js-apis-data-dataSharePredicates

openharmony 鸿蒙 capi-udmf-oh-udsappitem

openharmony 鸿蒙 capi-rdb-oh-data-vbuckets

openharmony 鸿蒙 capi-rdb-oh-predicates

openharmony 鸿蒙 capi-rdb-oh-data-value

openharmony 鸿蒙 capi-preferences-oh-preferencespair

openharmony 鸿蒙 errorcode-datashare

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