harmony 鸿蒙AbilityBase

2025-06-12 浏览 (1)

AbilityBase

Overview

As the basic definition module of Ability Kit, AbilityBase provides definitions and APIs for Want, which can be used to transfer information between application components.

System capability: SystemCapability.Ability.AbilityBase

Since: 15

Summary

Files

NameDescription
ability_base_common.hDeclares the error codes related to AbilityBase.
File to include: <AbilityKit/ability_base/ability_base_common.h>
Library: libability_base_want.so
want.hDeclares the capabilities related to Want.
File to include: <AbilityKit/ability_base/want.h>
Library: libability_base_want.so

Enums

NameDescription
AbilityBase_ErrorCode {
ABILITY_BASE_ERROR_CODE_NO_ERROR = 0,
ABILITY_BASE_ERROR_CODE_PARAM_INVALID = 401,
}
Enumerates the AbilityBase error codes.

Structs

NameDescription
AbilityBase_Element {
char* bundleName;
char* moduleName;
char* abilityName;
}
Element struct.
AbilityBase_WantWant struct.

Functions

NameDescription
AbilityBase_Want* OH_AbilityBase_CreateWant(AbilityBase_Element element)Creates Want.
AbilityBase_ErrorCode OH_AbilityBase_DestroyWant(AbilityBase_Want* want)Destroys Want. Want cannot be used after being destroyed. Otherwise, undefined behavior may occur.
AbilityBase_ErrorCode OH_AbilityBase_SetWantElement(AbilityBase_Want* want, AbilityBase_Element element)Sets the Element struct, which consists of bundleName, moduleName, and abilityName in Want.
AbilityBase_ErrorCode OH_AbilityBase_GetWantElement(AbilityBase_Want* want, AbilityBase_Element* element)Obtains the Element struct, which consists of bundleName, moduleName, and abilityName in Want.
AbilityBase_ErrorCode OH_AbilityBase_SetWantCharParam(AbilityBase_Want* want, const char* key, const char* value)Sets Param in Want. For details about Param, see parameters in Want.
AbilityBase_ErrorCode OH_AbilityBase_GetWantCharParam(AbilityBase_Want* want, const char* key, char* value, size_t valueSize)Obtains Param set by OH_AbilityBase_SetWantCharParam in Want.
AbilityBase_ErrorCode OH_AbilityBase_AddWantFd(AbilityBase_Want* want, const char* key, int32_t fd)Adds a Want file descriptor. The file descriptor can be obtained through fs.open.
AbilityBase_ErrorCode OH_AbilityBase_GetWantFd(AbilityBase_Want* want, const char* key, int32_t* fd)Obtains a Want file descriptor.
AbilityBase_ErrorCode OH_AbilityBase_SetWantUri(AbilityBase_Want* want, const char* uri)Sets uri in Want. For details about uri, see uri in Want.
AbilityBase_ErrorCode OH_AbilityBase_GetWantUri(AbilityBase_Want* want, char* uri, size_t uriSize)Obtains uri set in Want. For details about uri, see uri in Want.
AbilityBase_ErrorCode OH_AbilityBase_SetWantInt32Param(AbilityBase_Want* want, const char* key, int32_t value)Sets a value of the int32_t type in Want.
AbilityBase_ErrorCode OH_AbilityBase_GetWantInt32Param(AbilityBase_Want* want, const char* key, int32_t* value)Obtains a value of the int32_t type set in Want.
AbilityBase_ErrorCode OH_AbilityBase_SetWantBoolParam(AbilityBase_Want* want, const char* key, bool value)Sets a value of the bool type in Want.
AbilityBase_ErrorCode OH_AbilityBase_GetWantBoolParam(AbilityBase_Want* want, const char* key, bool* value)Obtains a value of the bool type set in Want.
AbilityBase_ErrorCode OH_AbilityBase_SetWantDoubleParam(AbilityBase_Want* want, const char* key, double value)Sets a value of the double type in Want.
AbilityBase_ErrorCode OH_AbilityBase_GetWantDoubleParam(AbilityBase_Want* want, const char* key, double* value)Obtains a value of the double type set in Want.

Enum Description

AbilityBase_ErrorCode

enum AbilityBase_ErrorCode

Description

Enumerates the AbilityBase error codes.

Since: 15

ValueDescription
ABILITY_BASE_ERROR_CODE_NO_ERROROperation successful.
ABILITY_BASE_ERROR_CODE_PARAM_INVALIDInvalid parameter.

Struct Description

AbilityBase_Want

AbilityBase_Want

Description

Want struct.

Since: 15

Function Description

OH_AbilityBase_CreateWant

AbilityBase_Want* OH_AbilityBase_CreateWant(AbilityBase_Element element)

Description

Creates Want.

Since: 15

Parameters

NameDescription
elementElement struct.

Returns

Returns AbilityBase_Want, which is a Want struct.

OH_AbilityBase_DestroyWant

AbilityBase_ErrorCode OH_AbilityBase_DestroyWant(AbilityBase_Want* want)

Description

Destroys Want. Want cannot be used after being destroyed. Otherwise, undefined behavior may occur.

Since: 15

Parameters

NameDescription
wantPointer to Want.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if Want is destroyed.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if element is invalid.

OH_AbilityBase_SetWantElement

AbilityBase_ErrorCode OH_AbilityBase_SetWantElement(AbilityBase_Want* want, AbilityBase_Element element)

Description

Sets the Element struct, which consists of bundleName, moduleName, and abilityName in Want.

Since: 15

Parameters

NameDescription
wantPointer to Want.
elementElement struct.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the setting is successful.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is set to a null pointer or element is invalid.

OH_AbilityBase_GetWantElement

AbilityBase_ErrorCode OH_AbilityBase_GetWantElement(AbilityBase_Want* want, AbilityBase_Element* element)

Description

Obtains the Element struct, which consists of bundleName, moduleName, and abilityName in Want.

Since: 15

Parameters

NameDescription
wantPointer to Want.
elementPointer to the Element struct.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the element struct is obtained.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is set to a null pointer or element is invalid.

OH_AbilityBase_SetWantCharParam

AbilityBase_ErrorCode OH_AbilityBase_SetWantCharParam(AbilityBase_Want* want, const char* key, const char* value)

Description

Sets Param in Want. For details about Param, see parameters in Want.

Since: 15

Parameters

NameDescription
wantPointer to Want.
keyPointer to a key in Want.
valuePointer to the value of the key in Want.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the setting is successful.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

OH_AbilityBase_GetWantCharParam

AbilityBase_ErrorCode OH_AbilityBase_GetWantCharParam(AbilityBase_Want* want, const char* key, char* value, size_t valueSize)

Description

Obtains Param set by OH_AbilityBase_SetWantCharParam in Want.

Since: 15

Parameters

NameDescription
wantPointer to Want.
keyPointer to a key in Want.
valuePointer to the value of the key in Want.
valueSizeLength of the value string. If valueSize is less than the actual value length, the ABILITY_BASE_ERROR_CODE_PARAM_INVALID error is reported.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the param struct is obtained.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

OH_AbilityBase_AddWantFd

AbilityBase_ErrorCode OH_AbilityBase_AddWantFd(AbilityBase_Want* want, const char* key, int32_t fd)

Description

Adds a Want file descriptor. The file descriptor can be obtained through fs.open.

Since: 15

Parameters

NameDescription
wantPointer to Want.
keyPointer to a key in Want.
fdFile descriptor, which is obtained by calling fs.open.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the Want file descriptor is added.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

OH_AbilityBase_GetWantFd

AbilityBase_ErrorCode OH_AbilityBase_GetWantFd(AbilityBase_Want* want, const char* key, int32_t* fd)

Description

Obtains a Want file descriptor.

Since: 15

Parameters

NameDescription
wantPointer to Want.
keyPointer to a key in Want.
fdPointer to the file descriptor.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the Want file descriptor is obtained.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

OH_AbilityBase_SetWantUri

AbilityBase_ErrorCode OH_AbilityBase_SetWantUri(AbilityBase_Want* want, const char* uri)

Description

Sets uri in Want. For details about uri, see uri in Want.

Since: 17

Parameters

NameDescription
wantPointer to Want.
uriPointer to a URI. If a URI is specified in Want, Want will match the specified URI information. For details, see uri in Want.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the setting is successful.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

OH_AbilityBase_GetWantUri

AbilityBase_ErrorCode OH_AbilityBase_GetWantUri(AbilityBase_Want* want, char* uri, size_t uriSize)

Description

Obtains uri set in Want. For details about uri, see uri in Want.

Since: 17

Parameters

NameDescription
wantPointer to Want.
uriPointer to a URI. If a URI is specified in Want, Want will match the specified URI information. For details, see uri in Want.
uriSizeLength of the URI string. If uriSize is less than the actual URI length, the ABILITY_BASE_ERROR_CODE_PARAM_INVALID error is reported.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the URI string in Want is successfully obtained.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

OH_AbilityBase_SetWantInt32Param

AbilityBase_ErrorCode OH_AbilityBase_SetWantInt32Param(AbilityBase_Want* want, const char* key, int32_t value)

Description

Sets a value of the int32_t type in Want.

Since: 17

Parameters

NameDescription
wantPointer to Want.
keyPointer to the key in Want.
valueValue of the int32_t type of the key.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the setting is successful.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

OH_AbilityBase_GetWantInt32Param

AbilityBase_ErrorCode OH_AbilityBase_GetWantInt32Param(AbilityBase_Want* want, const char* key, int32_t* value)

Description

Obtains a value of the int32_t type set in Want.

Since: 17

Parameters

NameDescription
wantPointer to Want.
keyPointer to the key in Want.
valuePointer to the value of the int32_t type of the key.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the value of the int32_t type is successfully obtained.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

OH_AbilityBase_SetWantBoolParam

AbilityBase_ErrorCode OH_AbilityBase_SetWantBoolParam(AbilityBase_Want* want, const char* key, bool value)

Description

Sets a value of the bool type in Want.

Since: 17

Parameters

NameDescription
wantPointer to Want.
keyPointer to the key in Want.
valueValue of the bool type of the key.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the setting is successful.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

OH_AbilityBase_GetWantBoolParam

AbilityBase_ErrorCode OH_AbilityBase_GetWantBoolParam(AbilityBase_Want* want, const char* key, bool* value)

Description

Obtains a value of the bool type set in Want.

Since: 17

Parameters

NameDescription
wantPointer to Want.
keyPointer to the key in Want.
valuePointer to the value of the bool type of the key.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the value of the bool type is successfully obtained.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

OH_AbilityBase_SetWantDoubleParam

AbilityBase_ErrorCode OH_AbilityBase_SetWantDoubleParam(AbilityBase_Want* want, const char* key, double value)

Description

Sets a value of the double type in Want.

Since: 17

Parameters

NameDescription
wantPointer to Want.
keyPointer to the key in Want.
valueValue of the double type of the key.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the setting is successful.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

OH_AbilityBase_GetWantDoubleParam

AbilityBase_ErrorCode OH_AbilityBase_GetWantDoubleParam(AbilityBase_Want* want, const char* key, double* value)

Description

Obtains a value of the double type set in Want.

Since: 17

Parameters

NameDescription
wantPointer to Want.
keyPointer to the key in Want.
valuePointer to the value of the double type of the key.

Returns

Returns ABILITY_BASE_ERROR_CODE_NO_ERROR if the value of the double type is successfully obtained.

Returns ABILITY_BASE_ERROR_CODE_PARAM_INVALID if want is a null pointer or invalid.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit

harmony 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

harmony 鸿蒙ability_runtime_common.h

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