1# oh_commonevent.h 2 3<!--Kit: Basic Services Kit--> 4<!--Subsystem: Notification--> 5<!--Owner: @michael_woo888--> 6<!--Designer: @dongqingran; @wulong158--> 7<!--Tester: @wanghong1997--> 8<!--Adviser: @huipeizi--> 9 10## 概述 11 12定义公共事件订阅与退订API接口与枚举错误码。 13 14**库:** libohcommonevent.so 15 16**系统能力:** SystemCapability.Notification.CommonEvent 17 18**起始版本:** 12 19 20**相关模块:** [OH_CommonEvent](capi-oh-commonevent.md) 21 22## 汇总 23 24### 结构体 25 26| 名称 | typedef关键字 | 描述 | 27| -- | -- | -- | 28| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md) | CommonEvent_SubscribeInfo | 提供CommonEvent_SubscribeInfo订阅者信息结构体声明。 | 29| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md) | CommonEvent_PublishInfo | 发布公共事件时使用的公共事件属性对象。 | 30| [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md) | CommonEvent_RcvData | 提供CommonEvent_RcvData公共事件回调数据结构体声明。 | 31 32### 变量 33 34| 名称 | typedef关键字 | 描述 | 35|----|------------|----| 36| void | CommonEvent_Subscriber | 提供CommonEvent_Subscriber订阅者结构体声明。 | 37| void | CommonEvent_Parameters | 提供CommonEvent_RcvData公共事件附件信息结构体声明。 | 38 39### 枚举 40 41| 名称 | typedef关键字 | 描述 | 42| -- | -- | -- | 43| [CommonEvent_ErrCode](#commonevent_errcode) | CommonEvent_ErrCode | 枚举错误码。 | 44 45### 函数 46 47| 名称 | typedef关键字 | 描述 | 48| -- | -- | -- | 49| [typedef void (\*CommonEvent_ReceiveCallback)(const CommonEvent_RcvData *data)](#commonevent_receivecallback) | CommonEvent_ReceiveCallback | 提供CommonEvent_ReceiveCallback回调函数声明。 | 50| [CommonEvent_SubscribeInfo* OH_CommonEvent_CreateSubscribeInfo(const char* events[], int32_t eventsNum)](#oh_commonevent_createsubscribeinfo) | - | 创建订阅者信息。 | 51| [CommonEvent_ErrCode OH_CommonEvent_SetPublisherPermission(CommonEvent_SubscribeInfo* info, const char* permission)](#oh_commonevent_setpublisherpermission) | - | 设置订阅者权限。 | 52| [CommonEvent_ErrCode OH_CommonEvent_SetPublisherBundleName(CommonEvent_SubscribeInfo* info, const char* bundleName)](#oh_commonevent_setpublisherbundlename) | - | 设置订阅者包名称。 | 53| [void OH_CommonEvent_DestroySubscribeInfo(CommonEvent_SubscribeInfo* info)](#oh_commonevent_destroysubscribeinfo) | - | 释放订阅者信息。 | 54| [CommonEvent_Subscriber* OH_CommonEvent_CreateSubscriber(const CommonEvent_SubscribeInfo* info,CommonEvent_ReceiveCallback callback)](#oh_commonevent_createsubscriber) | - | 创建订阅者。 | 55| [void OH_CommonEvent_DestroySubscriber(CommonEvent_Subscriber* subscriber)](#oh_commonevent_destroysubscriber) | - | 释放订阅者。 | 56| [CommonEvent_ErrCode OH_CommonEvent_Subscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_subscribe) | - | 订阅公共事件。 | 57| [CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_unsubscribe) | - | 退订公共事件。 | 58| [const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_geteventfromrcvdata) | - | 获取当前接收的公共事件名称。 | 59| [int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getcodefromrcvdata) | - | 获取接收到的公共事件数据(number类型)。 | 60| [const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getdatastrfromrcvdata) | - | 获取接收到的公共事件数据(string类型)。 | 61| [const char* OH_CommonEvent_GetBundleNameFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getbundlenamefromrcvdata) | - | 获取接收到的公共事件的包名称信息。 | 62| [const CommonEvent_Parameters* OH_CommonEvent_GetParametersFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getparametersfromrcvdata) | - | 获取接收到的公共事件的附加信息。 | 63| [CommonEvent_PublishInfo* OH_CommonEvent_CreatePublishInfo(bool ordered)](#oh_commonevent_createpublishinfo) | - | 创建公共事件属性对象。 | 64| [void OH_CommonEvent_DestroyPublishInfo(CommonEvent_PublishInfo* info)](#oh_commonevent_destroypublishinfo) | - | 销毁公共事件属性对象。 | 65| [CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoBundleName(CommonEvent_PublishInfo* info, const char* bundleName)](#oh_commonevent_setpublishinfobundlename) | - | 设置公共事件订阅者包名称。 | 66| [CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoPermissions(CommonEvent_PublishInfo* info,const char* permissions[], int32_t num)](#oh_commonevent_setpublishinfopermissions) | - | 设置公共事件订阅者权限。 | 67| [CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoCode(CommonEvent_PublishInfo* info, int32_t code)](#oh_commonevent_setpublishinfocode) | - | 设置公共事件传递的数据(number类型)。 | 68| [CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoData(CommonEvent_PublishInfo* info,const char* data, size_t length)](#oh_commonevent_setpublishinfodata) | - | 设置公共事件传递的数据(string类型)。 | 69| [CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoParameters(CommonEvent_PublishInfo* info,CommonEvent_Parameters* param)](#oh_commonevent_setpublishinfoparameters) | - | 设置公共事件传递的附加信息。 | 70| [CommonEvent_Parameters* OH_CommonEvent_CreateParameters()](#oh_commonevent_createparameters) | - | 创建公共事件附加信息对象。 | 71| [void OH_CommonEvent_DestroyParameters(CommonEvent_Parameters* param)](#oh_commonevent_destroyparameters) | - | 销毁公共事件附加信息对象。 | 72| [bool OH_CommonEvent_HasKeyInParameters(const CommonEvent_Parameters* para, const char* key)](#oh_commonevent_haskeyinparameters) | - | 检查附加信息中是否包含键值对信息。 | 73| [int OH_CommonEvent_GetIntFromParameters(const CommonEvent_Parameters* para, const char* key, const int defaultValue)](#oh_commonevent_getintfromparameters) | - | 获取公共事件附加信息中键为key的int类型内容。 | 74| [CommonEvent_ErrCode OH_CommonEvent_SetIntToParameters(CommonEvent_Parameters* param, const char* key, int value)](#oh_commonevent_setinttoparameters) | - | 设置公共事件附加信息的int类型内容。 | 75| [int32_t OH_CommonEvent_GetIntArrayFromParameters(const CommonEvent_Parameters* para, const char* key, int** array)](#oh_commonevent_getintarrayfromparameters) | - | 获取公共事件附加信息中键为key的int数组数据。 | 76| [CommonEvent_ErrCode OH_CommonEvent_SetIntArrayToParameters(CommonEvent_Parameters* param, const char* key,const int* value, size_t num)](#oh_commonevent_setintarraytoparameters) | - | 设置公共事件附加信息的int数组内容。 | 77| [long OH_CommonEvent_GetLongFromParameters(const CommonEvent_Parameters* para, const char* key, const long defaultValue)](#oh_commonevent_getlongfromparameters) | - | 获取公共事件附加信息中键为key的long类型数据。 | 78| [CommonEvent_ErrCode OH_CommonEvent_SetLongToParameters(CommonEvent_Parameters* param, const char* key, long value)](#oh_commonevent_setlongtoparameters) | - | 设置公共事件附加信息的long类型内容。 | 79| [int32_t OH_CommonEvent_GetLongArrayFromParameters(const CommonEvent_Parameters* para, const char* key, long** array)](#oh_commonevent_getlongarrayfromparameters) | - | 获取公共事件附加信息的long数组内容。 | 80| [CommonEvent_ErrCode OH_CommonEvent_SetLongArrayToParameters(CommonEvent_Parameters* param, const char* key,const long* value, size_t num)](#oh_commonevent_setlongarraytoparameters) | - | 设置公共事件附加信息的long数组内容。 | 81| [bool OH_CommonEvent_GetBoolFromParameters(const CommonEvent_Parameters* para, const char* key, const bool defaultValue)](#oh_commonevent_getboolfromparameters) | - | 获取公共事件附加信息中键为key的布尔类型数据。 | 82| [CommonEvent_ErrCode OH_CommonEvent_SetBoolToParameters(CommonEvent_Parameters* param, const char* key, bool value)](#oh_commonevent_setbooltoparameters) | - | 设置公共事件附加信息的布尔类型内容。 | 83| [int32_t OH_CommonEvent_GetBoolArrayFromParameters(const CommonEvent_Parameters* para, const char* key, bool** array)](#oh_commonevent_getboolarrayfromparameters) | - | 获取公共事件附加信息的布尔数组内容。 | 84| [CommonEvent_ErrCode OH_CommonEvent_SetBoolArrayToParameters(CommonEvent_Parameters* param, const char* key,const bool* value, size_t num)](#oh_commonevent_setboolarraytoparameters) | - | 设置公共事件附加信息的布尔数组内容。 | 85| [char OH_CommonEvent_GetCharFromParameters(const CommonEvent_Parameters* para, const char* key, const char defaultValue)](#oh_commonevent_getcharfromparameters) | - | 获取公共事件附加信息中键为key的字符类型数据。 | 86| [CommonEvent_ErrCode OH_CommonEvent_SetCharToParameters(CommonEvent_Parameters* param, const char* key, char value)](#oh_commonevent_setchartoparameters) | - | 设置公共事件附加信息的字符类型内容。 | 87| [int32_t OH_CommonEvent_GetCharArrayFromParameters(const CommonEvent_Parameters* para, const char* key, char** array)](#oh_commonevent_getchararrayfromparameters) | - | 获取公共事件附加信息的字符数组内容。 | 88| [CommonEvent_ErrCode OH_CommonEvent_SetCharArrayToParameters(CommonEvent_Parameters* param, const char* key,const char* value, size_t num)](#oh_commonevent_setchararraytoparameters) | - | 设置公共事件附加信息的字符数组内容。 | 89| [double OH_CommonEvent_GetDoubleFromParameters(const CommonEvent_Parameters* para, const char* key,const double defaultValue)](#oh_commonevent_getdoublefromparameters) | - | 获取公共事件附加信息的double类型内容。 | 90| [CommonEvent_ErrCode OH_CommonEvent_SetDoubleToParameters(CommonEvent_Parameters* param, const char* key,double value)](#oh_commonevent_setdoubletoparameters) | - | 设置公共事件附加信息的double类型内容。 | 91| [int32_t OH_CommonEvent_GetDoubleArrayFromParameters(const CommonEvent_Parameters* para, const char* key,double** array)](#oh_commonevent_getdoublearrayfromparameters) | - | 获取公共事件附加信息中键为key的double数组数据。 | 92| [CommonEvent_ErrCode OH_CommonEvent_SetDoubleArrayToParameters(CommonEvent_Parameters* param, const char* key,const double* value, size_t num)](#oh_commonevent_setdoublearraytoparameters) | - | 设置公共事件附加信息的double数组内容。 | 93| [CommonEvent_ErrCode OH_CommonEvent_Publish(const char* event)](#oh_commonevent_publish) | - | 发布公共事件。 | 94| [CommonEvent_ErrCode OH_CommonEvent_PublishWithInfo(const char* event, const CommonEvent_PublishInfo* info)](#oh_commonevent_publishwithinfo) | - | 发布带有指定属性的公共事件。 | 95| [bool OH_CommonEvent_IsOrderedCommonEvent(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_isorderedcommonevent) | - | 查询当前公共事件是否为有序公共事件。 | 96| [bool OH_CommonEvent_FinishCommonEvent(CommonEvent_Subscriber* subscriber)](#oh_commonevent_finishcommonevent) | - | 用于订阅者结束对当前有序公共事件的处理。 | 97| [bool OH_CommonEvent_GetAbortCommonEvent(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_getabortcommonevent) | - | 获取当前有序公共事件是否处于中止状态。 | 98| [bool OH_CommonEvent_AbortCommonEvent(CommonEvent_Subscriber* subscriber)](#oh_commonevent_abortcommonevent) | - | 该接口与[OH_CommonEvent_FinishCommonEvent](#oh_commonevent_finishcommonevent)配合使用,可以中止当前的有序公共事件,使该公共事件不再向下一个订阅者传递。 | 99| [bool OH_CommonEvent_ClearAbortCommonEvent(CommonEvent_Subscriber* subscriber)](#oh_commonevent_clearabortcommonevent) | - | 该接口与[OH_CommonEvent_FinishCommonEvent](#oh_commonevent_finishcommonevent)配合使用,可以取消当前有序公共事件的中止状态,使该公共事件继续向下一个订阅者传递。 | 100| [int32_t OH_CommonEvent_GetCodeFromSubscriber(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_getcodefromsubscriber) | - | 获取有序公共事件传递的数据(number类型)。 | 101| [bool OH_CommonEvent_SetCodeToSubscriber(CommonEvent_Subscriber* subscriber, int32_t code)](#oh_commonevent_setcodetosubscriber) | - | 设置有序公共事件传递的数据(number类型)。 | 102| [const char* OH_CommonEvent_GetDataFromSubscriber(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_getdatafromsubscriber) | - | 获取有序公共事件传递的数据(string类型)。 | 103| [bool OH_CommonEvent_SetDataToSubscriber(CommonEvent_Subscriber* subscriber, const char* data, size_t length)](#oh_commonevent_setdatatosubscriber) | - | 设置有序公共事件传递的数据(string类型)。 | 104 105## 枚举类型说明 106 107### CommonEvent_ErrCode 108 109``` 110enum CommonEvent_ErrCode 111``` 112 113**描述** 114 115枚举错误码。 116 117**起始版本:** 12 118 119| 枚举项 | 描述 | 120| -- | -- | 121| COMMONEVENT_ERR_OK = 0 | 成功。 | 122| COMMONEVENT_ERR_PERMISSION_ERROR = 201 | 权限错误。 | 123| COMMONEVENT_ERR_INVALID_PARAMETER = 401 | 参数错误。 | 124| COMMONEVENT_ERR_SENDING_LIMIT_EXCEEDED = 1500003| 事件发送频率过高。<br>**起始版本:** 20 | 125| COMMONEVENT_ERR_NOT_SYSTEM_SERVICE = 1500004 | 三方应用无法发送系统公共事件。 | 126| COMMONEVENT_ERR_SENDING_REQUEST_FAILED = 1500007 | IPC发送失败。 | 127| COMMONEVENT_ERR_INIT_UNDONE = 1500008 | 服务未初始化。 | 128| COMMONEVENT_ERR_OBTAIN_SYSTEM_PARAMS = 1500009 | 系统错误。 | 129| COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED = 1500010 | 订阅者数量超过限制。 | 130| COMMONEVENT_ERR_ALLOC_MEMORY_FAILED = 1500011 | 内存分配失败。 | 131 132 133## 函数说明 134 135### CommonEvent_ReceiveCallback() 136 137``` 138typedef void (*CommonEvent_ReceiveCallback)(const CommonEvent_RcvData *data) 139``` 140 141**描述** 142 143提供CommonEvent_ReceiveCallback回调函数声明。 144 145**起始版本:** 12 146 147 148**参数:** 149 150| 参数项 | 描述 | 151|-------------------------------------| -- | 152| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md) *data | 公共事件回调数据。 | 153 154### OH_CommonEvent_CreateSubscribeInfo() 155 156``` 157CommonEvent_SubscribeInfo* OH_CommonEvent_CreateSubscribeInfo(const char* events[], int32_t eventsNum) 158``` 159 160**描述** 161 162创建订阅者信息。 163 164**起始版本:** 12 165 166 167**参数:** 168 169| 参数项 | 描述 | 170| -- | -- | 171| const char* events[] | 订阅的公共事件。 | 172| int32_t eventsNum | 订阅的公共事件数量。 | 173 174**返回:** 175 176| 类型 | 说明 | 177|--------------------------------| -- | 178| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* | 成功则返回订阅者信息,失败则返回NULL。 | 179 180### OH_CommonEvent_SetPublisherPermission() 181 182``` 183CommonEvent_ErrCode OH_CommonEvent_SetPublisherPermission(CommonEvent_SubscribeInfo* info, const char* permission) 184``` 185 186**描述** 187 188设置订阅者权限。 189 190**起始版本:** 12 191 192 193**参数:** 194 195| 参数项 | 描述 | 196| -- | -- | 197| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* info | 订阅者信息。 | 198| const char* permission | 权限名称。 | 199 200**返回:** 201 202| 类型 | 说明 | 203| -- | -- | 204| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 205 206### OH_CommonEvent_SetPublisherBundleName() 207 208``` 209CommonEvent_ErrCode OH_CommonEvent_SetPublisherBundleName(CommonEvent_SubscribeInfo* info, const char* bundleName) 210``` 211 212**描述** 213 214设置订阅者包名称。 215 216**起始版本:** 12 217 218 219**参数:** 220 221| 参数项 | 描述 | 222| -- | -- | 223| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* info | 订阅者信息。 | 224| const char* bundleName | 包名称。 | 225 226**返回:** 227 228| 类型 | 说明 | 229| -- | -- | 230| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 231 232### OH_CommonEvent_DestroySubscribeInfo() 233 234``` 235void OH_CommonEvent_DestroySubscribeInfo(CommonEvent_SubscribeInfo* info) 236``` 237 238**描述** 239 240释放订阅者信息。 241 242**起始版本:** 12 243 244 245**参数:** 246 247| 参数项 | 描述 | 248| -- | -- | 249| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* info | 订阅者信息。 | 250 251### OH_CommonEvent_CreateSubscriber() 252 253``` 254CommonEvent_Subscriber* OH_CommonEvent_CreateSubscriber(const CommonEvent_SubscribeInfo* info,CommonEvent_ReceiveCallback callback) 255``` 256 257**描述** 258 259创建订阅者。 260 261**起始版本:** 12 262 263 264**参数:** 265 266| 参数项 | 描述 | 267|----------------------------------------------------------------------| -- | 268| const [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* info | 订阅者信息。 | 269| [CommonEvent_ReceiveCallback](#commonevent_receivecallback) callback | 公共事件回调函数 | 270 271**返回:** 272 273| 类型 | 说明 | 274| -- | -- | 275| [CommonEvent_Subscriber](#变量)* | 成功则返回订阅者,失败则返回NULL。 | 276 277### OH_CommonEvent_DestroySubscriber() 278 279``` 280void OH_CommonEvent_DestroySubscriber(CommonEvent_Subscriber* subscriber) 281``` 282 283**描述** 284 285释放订阅者。 286 287**起始版本:** 12 288 289 290**参数:** 291 292| 参数项 | 描述 | 293| -- | -- | 294| [CommonEvent_Subscriber](#变量)* subscriber | 订阅者。 | 295 296### OH_CommonEvent_Subscribe() 297 298``` 299CommonEvent_ErrCode OH_CommonEvent_Subscribe(const CommonEvent_Subscriber* subscriber) 300``` 301 302**描述** 303 304订阅公共事件。 305 306**起始版本:** 12 307 308 309**参数:** 310 311| 参数项 | 描述 | 312| -- | -- | 313| const [CommonEvent_Subscriber](#变量)* subscriber | 订阅者。 | 314 315**返回:** 316 317| 类型 | 说明 | 318| -- | -- | 319| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数subscriber无效。<br> 返回[COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)表示IPC请求发送失败。<br> 返回[COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode)表示公共事件服务未初始化。<br> 返回[COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED](capi-oh-commonevent-h.md#commonevent_errcode)表示进程订阅者数量超过200个。<br> 返回[COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)系统分配内存失败。 | 320 321### OH_CommonEvent_UnSubscribe() 322 323``` 324CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber) 325``` 326 327**描述** 328 329退阅公共事件。 330 331**起始版本:** 12 332 333 334**参数:** 335 336| 参数项 | 描述 | 337| -- | -- | 338| const [CommonEvent_Subscriber](#变量)* subscriber | 订阅者。 | 339 340**返回:** 341 342| 类型 | 说明 | 343| -- | -- | 344| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数subscriber无效。<br> 返回[COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)表示IPC请求发送失败。<br> 返回[COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode)表示公共事件服务未初始化。 | 345 346### OH_CommonEvent_GetEventFromRcvData() 347 348``` 349const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvData) 350``` 351 352**描述** 353 354获取当前接收的公共事件名称。 355 356**起始版本:** 12 357 358 359**参数:** 360 361| 参数项 | 描述 | 362|----------------------------------------| -- | 363| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md)* rcvData | 公共事件回调数据。 | 364 365**返回:** 366 367| 类型 | 说明 | 368| -- | -- | 369| const char* | 返回事件名称。 | 370 371### OH_CommonEvent_GetCodeFromRcvData() 372 373``` 374int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData) 375``` 376 377**描述** 378 379获取公共事件传递的数据(number类型)。 380 381**起始版本:** 12 382 383 384**参数:** 385 386| 参数项 | 描述 | 387| -- | -- | 388| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md)* rcvData | 公共事件回调数据。 | 389 390**返回:** 391 392| 类型 | 说明 | 393| -- | -- | 394| int32_t | 返回公共事件传递的数据(number类型)。 | 395 396### OH_CommonEvent_GetDataStrFromRcvData() 397 398``` 399const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvData) 400``` 401 402**描述** 403 404获取公共事件传递的数据(string类型)。 405 406**起始版本:** 12 407 408 409**参数:** 410 411| 参数项 | 描述 | 412| -- | -- | 413| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md)* rcvData | 公共事件回调数据。 | 414 415**返回:** 416 417| 类型 | 说明 | 418| -- | -- | 419| const char* | 返回公共事件传递的数据(string类型)。 | 420 421### OH_CommonEvent_GetBundleNameFromRcvData() 422 423``` 424const char* OH_CommonEvent_GetBundleNameFromRcvData(const CommonEvent_RcvData* rcvData) 425``` 426 427**描述** 428 429获取接收到的公共事件的包名称信息。 430 431**起始版本:** 12 432 433 434**参数:** 435 436| 参数项 | 描述 | 437| -- | -- | 438| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md)* rcvData | 公共事件回调数据。 | 439 440**返回:** 441 442| 类型 | 说明 | 443| -- | -- | 444| const char* | 返回公共事件的包名称。 | 445 446### OH_CommonEvent_GetParametersFromRcvData() 447 448``` 449const CommonEvent_Parameters* OH_CommonEvent_GetParametersFromRcvData(const CommonEvent_RcvData* rcvData) 450``` 451 452**描述** 453 454获取公共事件附加信息。 455 456**起始版本:** 12 457 458 459**参数:** 460 461| 参数项 | 描述 | 462| -- | -- | 463| const [CommonEvent_RcvData](capi-oh-commonevent-commonevent-rcvdata.md)* rcvData | 公共事件回调数据。 | 464 465**返回:** 466 467| 类型 | 说明 | 468| -- | -- | 469| const [CommonEvent_Parameters](#变量)* | 返回公共事件附加信息。 | 470 471### OH_CommonEvent_CreatePublishInfo() 472 473``` 474CommonEvent_PublishInfo* OH_CommonEvent_CreatePublishInfo(bool ordered) 475``` 476 477**描述** 478 479创建公共事件属性对象。 480 481**起始版本:** 18 482 483 484**参数:** 485 486| 参数项 | 描述 | 487| -- | -- | 488| bool ordered | 是否为有序公共事件。<br> - true:有序公共事件。<br> - false:无序公共事件。 | 489 490**返回:** 491 492| 类型 | 说明 | 493|------------------------------| -- | 494| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* | 创建的公共事件属性对象,创建失败时,返回null。 | 495 496### OH_CommonEvent_DestroyPublishInfo() 497 498``` 499void OH_CommonEvent_DestroyPublishInfo(CommonEvent_PublishInfo* info) 500``` 501 502**描述** 503 504销毁公共事件属性对象。 505 506**起始版本:** 18 507 508 509**参数:** 510 511| 参数项 | 描述 | 512| -- | -- | 513| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 要销毁的公共事件属性对象。 | 514 515### OH_CommonEvent_SetPublishInfoBundleName() 516 517``` 518CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoBundleName(CommonEvent_PublishInfo* info, const char* bundleName) 519``` 520 521**描述** 522 523设置公共事件订阅者包名称。 524 525**起始版本:** 18 526 527 528**参数:** 529 530| 参数项 | 描述 | 531| -- | -- | 532| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 公共事件属性对象。 | 533| const char* bundleName | 设置的订阅者包名称。 | 534 535**返回:** 536 537| 类型 | 说明 | 538| -- | -- | 539| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 540 541### OH_CommonEvent_SetPublishInfoPermissions() 542 543``` 544CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoPermissions(CommonEvent_PublishInfo* info,const char* permissions[], int32_t num) 545``` 546 547**描述** 548 549设置公共事件订阅者权限。 550 551**起始版本:** 18 552 553 554**参数:** 555 556| 参数项 | 描述 | 557| -- | -- | 558| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 公共事件属性对象。 | 559| const char* permissions[] | 订阅者权限名称数组。 | 560| int32_t num | 权限的数量。 | 561 562**返回:** 563 564| 类型 | 说明 | 565| -- | -- | 566| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 567 568### OH_CommonEvent_SetPublishInfoCode() 569 570``` 571CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoCode(CommonEvent_PublishInfo* info, int32_t code) 572``` 573 574**描述** 575 576设置公共事件传递的数据(number类型)。 577 578**起始版本:** 18 579 580 581**参数:** 582 583| 参数项 | 描述 | 584| -- | -- | 585| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 公共事件属性对象。 | 586| int32_t code | 公共事件传递的数据(number类型)。 | 587 588**返回:** 589 590| 类型 | 说明 | 591| -- | -- | 592| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 593 594### OH_CommonEvent_SetPublishInfoData() 595 596``` 597CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoData(CommonEvent_PublishInfo* info,const char* data, size_t length) 598``` 599 600**描述** 601 602设置公共事件传递的数据(string类型)。 603 604**起始版本:** 18 605 606 607**参数:** 608 609| 参数项 | 描述 | 610| -- | -- | 611| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 公共事件属性对象。 | 612| const char* data | 公共事件传递的数据(string类型)。 | 613| size_t length | 结果数据的长度。 | 614 615**返回:** 616 617| 类型 | 说明 | 618| -- | -- | 619| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 620 621### OH_CommonEvent_SetPublishInfoParameters() 622 623``` 624CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoParameters(CommonEvent_PublishInfo* info,CommonEvent_Parameters* param) 625``` 626 627**描述** 628 629设置公共事件附加信息。 630 631**起始版本:** 18 632 633 634**参数:** 635 636| 参数项 | 描述 | 637| -- | -- | 638| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 公共事件属性对象。 | 639| CommonEvent_Parameters* param | 设置的附加信息。 | 640 641**返回:** 642 643| 类型 | 说明 | 644| -- | -- | 645| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 646 647### OH_CommonEvent_CreateParameters() 648 649``` 650CommonEvent_Parameters* OH_CommonEvent_CreateParameters() 651``` 652 653**描述** 654 655创建公共事件附加信息对象。 656 657**起始版本:** 18 658 659**返回:** 660 661| 类型 | 说明 | 662| -- | -- | 663| [CommonEvent_Parameters](#变量)* | 返回公共事件附加信息,创建失败时,返回null。 | 664 665### OH_CommonEvent_DestroyParameters() 666 667``` 668void OH_CommonEvent_DestroyParameters(CommonEvent_Parameters* param) 669``` 670 671**描述** 672 673销毁公共事件附加信息对象。 674 675**起始版本:** 18 676 677 678**参数:** 679 680| 参数项 | 描述 | 681| -- | -- | 682| [CommonEvent_Parameters](#变量)* param | 公共事件附加信息。 | 683 684### OH_CommonEvent_HasKeyInParameters() 685 686``` 687bool OH_CommonEvent_HasKeyInParameters(const CommonEvent_Parameters* para, const char* key) 688``` 689 690**描述** 691 692检查附加信息中是否包含键值对信息。 693 694**起始版本:** 12 695 696 697**参数:** 698 699| 参数项 | 描述 | 700| -- | -- | 701| const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | 702| const char* key | 数据键。 | 703 704**返回:** 705 706| 类型 | 说明 | 707| -- | -- | 708| bool | 返回数据键是否存在。<br> - true:存在。<br> - false:不存在。 | 709 710### OH_CommonEvent_GetIntFromParameters() 711 712``` 713int OH_CommonEvent_GetIntFromParameters(const CommonEvent_Parameters* para, const char* key, const int defaultValue) 714``` 715 716**描述** 717 718获取公共事件附加信息中键为key的int类型内容。 719 720**起始版本:** 12 721 722 723**参数:** 724 725| 参数项 | 描述 | 726| -- | -- | 727| const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | 728| const char* key | 数据键。 | 729| const int defaultValue | 默认值。 | 730 731**返回:** 732 733| 类型 | 说明 | 734| -- | -- | 735| int | 返回查询的int类型数据。 | 736 737### OH_CommonEvent_SetIntToParameters() 738 739``` 740CommonEvent_ErrCode OH_CommonEvent_SetIntToParameters(CommonEvent_Parameters* param, const char* key, int value) 741``` 742 743**描述** 744 745设置公共事件附加信息的int类型内容。 746 747**起始版本:** 18 748 749 750**参数:** 751 752| 参数项 | 描述 | 753| -- | -- | 754| [CommonEvent_Parameters](#变量)* param | 公共事件附加信息。 | 755| const char* key | 数据键。 | 756| int value | 设置的int类型内容。 | 757 758**返回:** 759 760| 类型 | 说明 | 761| -- | -- | 762| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 763 764### OH_CommonEvent_GetIntArrayFromParameters() 765 766``` 767int32_t OH_CommonEvent_GetIntArrayFromParameters(const CommonEvent_Parameters* para, const char* key, int** array) 768``` 769 770**描述** 771 772获取公共事件附加信息中键为key的int数组数据。 773 774**起始版本:** 12 775 776 777**参数:** 778 779| 参数项 | 描述 | 780| -- | -- | 781| const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | 782| const char* key | 数据键。 | 783| int** array | 查询的数组。 | 784 785**返回:** 786 787| 类型 | 说明 | 788| -- | -- | 789| int32_t | 返回查询的数组长度,默认值为0。 | 790 791### OH_CommonEvent_SetIntArrayToParameters() 792 793``` 794CommonEvent_ErrCode OH_CommonEvent_SetIntArrayToParameters(CommonEvent_Parameters* param, const char* key,const int* value, size_t num) 795``` 796 797**描述** 798 799设置公共事件附加信息的int数组内容。 800 801**起始版本:** 18 802 803 804**参数:** 805 806| 参数项 | 描述 | 807| -- | -- | 808| [CommonEvent_Parameters](#变量)* param | 公共事件附加信息。 | 809| const char* key | 数据键。 | 810| const int* value | 设置的int数组内容。 | 811| size_t num | 设置的int数组内容中元素的个数。 | 812 813**返回:** 814 815| 类型 | 说明 | 816| -- | -- | 817| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。<br> 返回[COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)表示内存分配失败。 | 818 819### OH_CommonEvent_GetLongFromParameters() 820 821``` 822long OH_CommonEvent_GetLongFromParameters(const CommonEvent_Parameters* para, const char* key, const long defaultValue) 823``` 824 825**描述** 826 827获取公共事件附加信息中键为key的long类型数据。 828 829**起始版本:** 12 830 831 832**参数:** 833 834| 参数项 | 描述 | 835| -- | -- | 836| const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | 837| const char* key | 数据键。 | 838| const long defaultValue | 默认值。 | 839 840**返回:** 841 842| 类型 | 说明 | 843| -- | -- | 844| long | 返回查询的long类型数据。 | 845 846### OH_CommonEvent_SetLongToParameters() 847 848``` 849CommonEvent_ErrCode OH_CommonEvent_SetLongToParameters(CommonEvent_Parameters* param, const char* key, long value) 850``` 851 852**描述** 853 854设置公共事件附加信息的long类型内容。 855 856**起始版本:** 18 857 858 859**参数:** 860 861| 参数项 | 描述 | 862| -- | -- | 863| [CommonEvent_Parameters](#变量)* param | 公共事件附加信息。 | 864| const char* key | 数据键。 | 865| long value | 设置的long类型内容。 | 866 867**返回:** 868 869| 类型 | 说明 | 870| -- | -- | 871| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 872 873### OH_CommonEvent_GetLongArrayFromParameters() 874 875``` 876int32_t OH_CommonEvent_GetLongArrayFromParameters(const CommonEvent_Parameters* para, const char* key, long** array) 877``` 878 879**描述** 880 881获取公共事件附加信息的long数组内容。 882 883**起始版本:** 12 884 885 886**参数:** 887 888| 参数项 | 描述 | 889| -- | -- | 890| const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | 891| const char* key | 数据键。 | 892| long** array | 查询的数组。 | 893 894**返回:** 895 896| 类型 | 说明 | 897| -- | -- | 898| int32_t | 返回查询的数组长度,默认值为0。 | 899 900### OH_CommonEvent_SetLongArrayToParameters() 901 902``` 903CommonEvent_ErrCode OH_CommonEvent_SetLongArrayToParameters(CommonEvent_Parameters* param, const char* key,const long* value, size_t num) 904``` 905 906**描述** 907 908设置公共事件附加信息的long数组内容。 909 910**起始版本:** 18 911 912 913**参数:** 914 915| 参数项 | 描述 | 916| -- | -- | 917| [CommonEvent_Parameters](#变量)* param | 公共事件附加信息。 | 918| const char* key | 数据键。 | 919| const long* value | 设置的long数组内容。 | 920| size_t num | 设置的long数组内容中元素的个数。 | 921 922**返回:** 923 924| 类型 | 说明 | 925| -- | -- | 926| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。<br> 返回[COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)表示内存分配失败。 | 927 928### OH_CommonEvent_GetBoolFromParameters() 929 930``` 931bool OH_CommonEvent_GetBoolFromParameters(const CommonEvent_Parameters* para, const char* key, const bool defaultValue) 932``` 933 934**描述** 935 936获取公共事件附加信息中键为key的布尔类型数据。 937 938**起始版本:** 12 939 940 941**参数:** 942 943| 参数项 | 描述 | 944| -- | -- | 945| const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | 946| const char* key | 数据键。 | 947| const bool defaultValue | 默认值。 | 948 949**返回:** 950 951| 类型 | 说明 | 952| -- | -- | 953| bool | 返回查询的bool类型数据。 | 954 955### OH_CommonEvent_SetBoolToParameters() 956 957``` 958CommonEvent_ErrCode OH_CommonEvent_SetBoolToParameters(CommonEvent_Parameters* param, const char* key, bool value) 959``` 960 961**描述** 962 963设置公共事件附加信息的布尔类型内容。 964 965**起始版本:** 18 966 967 968**参数:** 969 970| 参数项 | 描述 | 971| -- | -- | 972| [CommonEvent_Parameters](#变量)* param | 公共事件附加信息。 | 973| const char* key | 数据键。 | 974| bool value | 设置的布尔类型内容。 | 975 976**返回:** 977 978| 类型 | 说明 | 979| -- | -- | 980| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 981 982### OH_CommonEvent_GetBoolArrayFromParameters() 983 984``` 985int32_t OH_CommonEvent_GetBoolArrayFromParameters(const CommonEvent_Parameters* para, const char* key, bool** array) 986``` 987 988**描述** 989 990获取公共事件附加信息的布尔数组内容。 991 992**起始版本:** 12 993 994 995**参数:** 996 997| 参数项 | 描述 | 998| -- | -- | 999| const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | 1000| const char* key | 数据键。 | 1001| bool** array | 查询的数组。 | 1002 1003**返回:** 1004 1005| 类型 | 说明 | 1006| -- | -- | 1007| int32_t | 返回查询的数组长度,默认值为0。 | 1008 1009### OH_CommonEvent_SetBoolArrayToParameters() 1010 1011``` 1012CommonEvent_ErrCode OH_CommonEvent_SetBoolArrayToParameters(CommonEvent_Parameters* param, const char* key,const bool* value, size_t num) 1013``` 1014 1015**描述** 1016 1017设置公共事件附加信息的布尔数组内容。 1018 1019**起始版本:** 18 1020 1021 1022**参数:** 1023 1024| 参数项 | 描述 | 1025| -- | -- | 1026| [CommonEvent_Parameters](#变量)* param | 公共事件附加信息。 | 1027| const char* key | 数据键。 | 1028| const bool* value | 设置的布尔数组内容。 | 1029| size_t num | 设置的布尔数组内容中元素的个数。 | 1030 1031**返回:** 1032 1033| 类型 | 说明 | 1034| -- | -- | 1035| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。<br> 返回[COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)表示内存分配失败。 | 1036 1037### OH_CommonEvent_GetCharFromParameters() 1038 1039``` 1040char OH_CommonEvent_GetCharFromParameters(const CommonEvent_Parameters* para, const char* key, const char defaultValue) 1041``` 1042 1043**描述** 1044 1045获取公共事件附加信息中键为key的字符类型数据。 1046 1047**起始版本:** 12 1048 1049 1050**参数:** 1051 1052| 参数项 | 描述 | 1053| -- | -- | 1054| const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | 1055| const char* key | 数据键。 | 1056| const char defaultValue | 默认值。 | 1057 1058**返回:** 1059 1060| 类型 | 说明 | 1061| -- | -- | 1062| char | 返回查询的char类型数据。 | 1063 1064### OH_CommonEvent_SetCharToParameters() 1065 1066``` 1067CommonEvent_ErrCode OH_CommonEvent_SetCharToParameters(CommonEvent_Parameters* param, const char* key, char value) 1068``` 1069 1070**描述** 1071 1072设置公共事件附加信息的字符类型内容。 1073 1074**起始版本:** 18 1075 1076 1077**参数:** 1078 1079| 参数项 | 描述 | 1080| -- | -- | 1081| [CommonEvent_Parameters](#变量)* param | 公共事件附加信息。 | 1082| const char* key | 数据键。 | 1083| char value | 设置的字符类型内容。 | 1084 1085**返回:** 1086 1087| 类型 | 说明 | 1088| -- | -- | 1089| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 1090 1091### OH_CommonEvent_GetCharArrayFromParameters() 1092 1093``` 1094int32_t OH_CommonEvent_GetCharArrayFromParameters(const CommonEvent_Parameters* para, const char* key, char** array) 1095``` 1096 1097**描述** 1098 1099获取公共事件附加信息的字符数组内容。 1100 1101**起始版本:** 12 1102 1103 1104**参数:** 1105 1106| 参数项 | 描述 | 1107| -- | -- | 1108| const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | 1109| const char* key | 数据键。 | 1110| char** array | 查询的数组。 | 1111 1112**返回:** 1113 1114| 类型 | 说明 | 1115| -- | -- | 1116| int32_t | 返回查询的数组长度,默认值为0。 | 1117 1118### OH_CommonEvent_SetCharArrayToParameters() 1119 1120``` 1121CommonEvent_ErrCode OH_CommonEvent_SetCharArrayToParameters(CommonEvent_Parameters* param, const char* key,const char* value, size_t num) 1122``` 1123 1124**描述** 1125 1126设置公共事件附加信息的字符数组内容。 1127 1128**起始版本:** 18 1129 1130 1131**参数:** 1132 1133| 参数项 | 描述 | 1134| -- | -- | 1135| [CommonEvent_Parameters](#变量)* param | 公共事件附加信息。 | 1136| const char* key | 数据键。 | 1137| const char* value | 设置的字符数组内容。 | 1138| size_t num | 设置的字符数组内容中元素的个数。 | 1139 1140**返回:** 1141 1142| 类型 | 说明 | 1143| -- | -- | 1144| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 1145 1146### OH_CommonEvent_GetDoubleFromParameters() 1147 1148``` 1149double OH_CommonEvent_GetDoubleFromParameters(const CommonEvent_Parameters* para, const char* key,const double defaultValue) 1150``` 1151 1152**描述** 1153 1154获取公共事件附加信息的double类型内容。 1155 1156**起始版本:** 12 1157 1158 1159**参数:** 1160 1161| 参数项 | 描述 | 1162| -- | -- | 1163| const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | 1164| const char* key | 数据键。 | 1165| const double defaultValue | 默认值。 | 1166 1167**返回:** 1168 1169| 类型 | 说明 | 1170| -- | -- | 1171| double | 返回查询的double类型数据。 | 1172 1173### OH_CommonEvent_SetDoubleToParameters() 1174 1175``` 1176CommonEvent_ErrCode OH_CommonEvent_SetDoubleToParameters(CommonEvent_Parameters* param, const char* key,double value) 1177``` 1178 1179**描述** 1180 1181设置公共事件附加信息的double类型内容。 1182 1183**起始版本:** 18 1184 1185 1186**参数:** 1187 1188| 参数项 | 描述 | 1189| -- | -- | 1190| [CommonEvent_Parameters](#变量)* param | 公共事件附加信息。 | 1191| const char* key | 数据键。 | 1192| double value | 设置的double类型内容。 | 1193 1194**返回:** 1195 1196| 类型 | 说明 | 1197| -- | -- | 1198| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。 | 1199 1200### OH_CommonEvent_GetDoubleArrayFromParameters() 1201 1202``` 1203int32_t OH_CommonEvent_GetDoubleArrayFromParameters(const CommonEvent_Parameters* para, const char* key,double** array) 1204``` 1205 1206**描述** 1207 1208获取公共事件附加信息中键为key的double数组数据。 1209 1210**起始版本:** 12 1211 1212 1213**参数:** 1214 1215| 参数项 | 描述 | 1216| -- | -- | 1217| const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | 1218| const char* key | 数据键。 | 1219| double** array | 查询的数组。 | 1220 1221**返回:** 1222 1223| 类型 | 说明 | 1224| -- | -- | 1225| int32_t | 返回查询的数组长度,默认值为0。 | 1226 1227### OH_CommonEvent_SetDoubleArrayToParameters() 1228 1229``` 1230CommonEvent_ErrCode OH_CommonEvent_SetDoubleArrayToParameters(CommonEvent_Parameters* param, const char* key,const double* value, size_t num) 1231``` 1232 1233**描述** 1234 1235设置公共事件附加信息的double数组内容。 1236 1237**起始版本:** 18 1238 1239 1240**参数:** 1241 1242| 参数项 | 描述 | 1243| -- | -- | 1244| [CommonEvent_Parameters](#变量)* param | 公共事件附加信息。 | 1245| const char* key | 数据键。 | 1246| const double* value | 设置的double数组内容。 | 1247| size_t num | 设置的double数组内容中元素的个数。 | 1248 1249**返回:** 1250 1251| 类型 | 说明 | 1252| -- | -- | 1253| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。<br> 返回[COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)表示内存分配失败。 | 1254 1255### OH_CommonEvent_Publish() 1256 1257``` 1258CommonEvent_ErrCode OH_CommonEvent_Publish(const char* event) 1259``` 1260 1261**描述** 1262 1263发布公共事件。 1264 1265**起始版本:** 18 1266 1267 1268**参数:** 1269 1270| 参数项 | 描述 | 1271| -- | -- | 1272| const char* event | 公共事件名称。 | 1273 1274**返回:** 1275 1276| 类型 | 说明 | 1277| -- | -- | 1278| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。<br> 返回[COMMONEVENT_ERR_SENDING_LIMIT_EXCEEDED](capi-oh-commonevent-h.md#commonevent_errcode)表示事件发送频率过高。<br> 返回[COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)表示IPC请求发送失败。<br> 返回[COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode)表示公共事件服务未初始化。 | 1279 1280### OH_CommonEvent_PublishWithInfo() 1281 1282``` 1283CommonEvent_ErrCode OH_CommonEvent_PublishWithInfo(const char* event, const CommonEvent_PublishInfo* info) 1284``` 1285 1286**描述** 1287 1288发布带有指定属性的公共事件。 1289 1290**起始版本:** 18 1291 1292 1293**参数:** 1294 1295| 参数项 | 描述 | 1296| -- | -- | 1297| const char* event | 公共事件名称。 | 1298| const [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 设置的公共事件属性。 | 1299 1300**返回:** 1301 1302| 类型 | 说明 | 1303| -- | -- | 1304| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数错误。<br> 返回[COMMONEVENT_ERR_SENDING_LIMIT_EXCEEDED](capi-oh-commonevent-h.md#commonevent_errcode)表示事件发送频率过高。<br> 返回[COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)表示IPC请求发送失败。<br> 返回[COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode)表示公共事件服务未初始化。 | 1305 1306### OH_CommonEvent_IsOrderedCommonEvent() 1307 1308``` 1309bool OH_CommonEvent_IsOrderedCommonEvent(const CommonEvent_Subscriber* subscriber) 1310``` 1311 1312**描述** 1313 1314查询当前公共事件是否为有序公共事件。 1315 1316**起始版本:** 18 1317 1318 1319**参数:** 1320 1321| 参数项 | 描述 | 1322| -- | -- | 1323| const [CommonEvent_Subscriber](#变量)* subscriber | 公共事件的订阅者对象。 | 1324 1325**返回:** 1326 1327| 类型 | 说明 | 1328| -- | -- | 1329| bool | 返回true表示有序公共事件;返回false表示无序公共事件。 | 1330 1331### OH_CommonEvent_FinishCommonEvent() 1332 1333``` 1334bool OH_CommonEvent_FinishCommonEvent(CommonEvent_Subscriber* subscriber) 1335``` 1336 1337**描述** 1338 1339用于订阅者结束对当前有序公共事件的处理。 1340 1341**起始版本:** 18 1342 1343 1344**参数:** 1345 1346| 参数项 | 描述 | 1347| -- | -- | 1348| [CommonEvent_Subscriber](#变量)* subscriber | 公共事件的订阅者对象。 | 1349 1350**返回:** 1351 1352| 类型 | 说明 | 1353| -- | -- | 1354| bool | 返回true表示操作成功;返回false表示操作失败。 | 1355 1356### OH_CommonEvent_GetAbortCommonEvent() 1357 1358``` 1359bool OH_CommonEvent_GetAbortCommonEvent(const CommonEvent_Subscriber* subscriber) 1360``` 1361 1362**描述** 1363 1364获取当前有序公共事件是否处于中止状态。 1365 1366**起始版本:** 18 1367 1368 1369**参数:** 1370 1371| 参数项 | 描述 | 1372| -- | -- | 1373| const [CommonEvent_Subscriber](#变量)* subscriber | 公共事件的订阅者对象。 | 1374 1375**返回:** 1376 1377| 类型 | 说明 | 1378| -- | -- | 1379| bool | 返回true表示当前有序公共事件处于中止状态;返回false表示当前有序公共事件没有处于中止状态。 | 1380 1381### OH_CommonEvent_AbortCommonEvent() 1382 1383``` 1384bool OH_CommonEvent_AbortCommonEvent(CommonEvent_Subscriber* subscriber) 1385``` 1386 1387**描述** 1388 1389该接口与[OH_CommonEvent_FinishCommonEvent](#oh_commonevent_finishcommonevent)配合使用,可以中止当前的有序公共事件,使该公共事件不再向下一个订阅者传递。 1390 1391**起始版本:** 18 1392 1393 1394**参数:** 1395 1396| 参数项 | 描述 | 1397| -- | -- | 1398| [CommonEvent_Subscriber](#变量)* subscriber | 公共事件的订阅者对象。 | 1399 1400**返回:** 1401 1402| 类型 | 说明 | 1403| -- | -- | 1404| bool | 返回true表示操作成功;返回false表示操作失败。 | 1405 1406### OH_CommonEvent_ClearAbortCommonEvent() 1407 1408``` 1409bool OH_CommonEvent_ClearAbortCommonEvent(CommonEvent_Subscriber* subscriber) 1410``` 1411 1412**描述** 1413 1414该接口与[OH_CommonEvent_FinishCommonEvent](#oh_commonevent_finishcommonevent)配合使用,可以取消当前有序公共事件的中止状态,使该公共事件继续向下一个订阅者传递。 1415 1416**起始版本:** 18 1417 1418 1419**参数:** 1420 1421| 参数项 | 描述 | 1422| -- | -- | 1423| [CommonEvent_Subscriber](#变量)* subscriber | 公共事件的订阅者对象。 | 1424 1425**返回:** 1426 1427| 类型 | 说明 | 1428| -- | -- | 1429| bool | 返回true表示操作成功;返回false表示操作失败。 | 1430 1431### OH_CommonEvent_GetCodeFromSubscriber() 1432 1433``` 1434int32_t OH_CommonEvent_GetCodeFromSubscriber(const CommonEvent_Subscriber* subscriber) 1435``` 1436 1437**描述** 1438 1439获取有序公共事件传递的数据(number类型)。 1440 1441**起始版本:** 18 1442 1443 1444**参数:** 1445 1446| 参数项 | 描述 | 1447| -- | -- | 1448| const [CommonEvent_Subscriber](#变量)* subscriber | 公共事件的订阅者对象。 | 1449 1450**返回:** 1451 1452| 类型 | 说明 | 1453| -- | -- | 1454| int32_t | 返回有序公共事件传递的数据(number类型),无法获取时返回0。 | 1455 1456### OH_CommonEvent_SetCodeToSubscriber() 1457 1458``` 1459bool OH_CommonEvent_SetCodeToSubscriber(CommonEvent_Subscriber* subscriber, int32_t code) 1460``` 1461 1462**描述** 1463 1464设置有序公共事件传递的数据(number类型)。 1465 1466**起始版本:** 18 1467 1468 1469**参数:** 1470 1471| 参数项 | 描述 | 1472| -- | -- | 1473| [CommonEvent_Subscriber](#变量)* subscriber | 公共事件的订阅者对象。 | 1474| int32_t code | 有序公共事件传递的数据(number类型)。 | 1475 1476**返回:** 1477 1478| 类型 | 说明 | 1479| -- | -- | 1480| bool | 返回true表示操作成功;返回false表示操作失败。 | 1481 1482### OH_CommonEvent_GetDataFromSubscriber() 1483 1484``` 1485const char* OH_CommonEvent_GetDataFromSubscriber(const CommonEvent_Subscriber* subscriber) 1486``` 1487 1488**描述** 1489 1490获取有序公共事件传递的数据(string类型)。 1491 1492**起始版本:** 18 1493 1494 1495**参数:** 1496 1497| 参数项 | 描述 | 1498| -- | -- | 1499| const [CommonEvent_Subscriber](#变量)* subscriber | 公共事件的订阅者对象。 | 1500 1501**返回:** 1502 1503| 类型 | 说明 | 1504| -- | -- | 1505| const char* | 返回有序公共事件传递的数据(string类型),无法获取时返回null。 | 1506 1507### OH_CommonEvent_SetDataToSubscriber() 1508 1509``` 1510bool OH_CommonEvent_SetDataToSubscriber(CommonEvent_Subscriber* subscriber, const char* data, size_t length) 1511``` 1512 1513**描述** 1514 1515设置有序公共事件传递的数据(string类型)。 1516 1517**起始版本:** 18 1518 1519 1520**参数:** 1521 1522| 参数项 | 描述 | 1523| -- | -- | 1524| [CommonEvent_Subscriber](#变量)* subscriber | 公共事件的订阅者对象。 | 1525| const char* data | 有序公共事件传递的数据(string类型)。 | 1526| size_t length | 数据的长度。 | 1527 1528**返回:** 1529 1530| 类型 | 说明 | 1531| -- | -- | 1532| bool | 返回true表示操作成功;返回false表示操作失败。 | 1533 1534 1535