智能客服
你问我答,随时在线为你解决问题

























向系统通知去电消息是Call Kit提供的能力之一,用于收到网络音视频去电消息之后,开发者可以通过调用对应接口以便系统正确展示去电横幅通知。
应用在收到网络音视频去电消息后,应用内部建立需通话连接,建立成功后需调用此接口通知voipCall模块去电以便系统展示横幅,携带通话信息,详情见VoipCallAttribute。为保证用户头像可以正常显示,头像图片大小需控制在100Kb以内。为了保证用户头像显示清晰,请传入的头像像素固定为32vp。
通知去电消息,使用Promise异步回调,具体API说明详见接口文档。
接口名 | 描述 |
|---|---|
reportOutgoingCall(voipCallAttribute: VoipCallAttribute): Promise<ErrorReason> | 向系统通知去电,需携带详细信息。 |
import { image } from '@kit.ImageKit'; import { voipCall } from '@kit.CallKit'; import { resourceManager } from '@kit.LocalizationKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { UIAbility } from '@kit.AbilityKit'; import { pushService } from '@kit.PushKit'; interface Content { data: string; callId: string; } export default class VoipExtAbility extends UIAbility { onCreate(): void { hilog.info(0x0000, 'testTag', 'VoipExtAbility onCreate.'); pushService.receiveMessage('VoIP', this, async (data) => { let content: Content = JSON.parse(data.data); let callId: string = content.callId; hilog.info(0x0000, 'testTag', 'Get voip message successfully: %{public}s', callId); // 此处为用户头像,需要创建PixelMap类型 const resourceMgr : resourceManager.ResourceManager = this.context.resourceManager; const fileData : Uint8Array = await resourceMgr.getRawFileContent('example.png'); const buffer = fileData.buffer; const imageSource : image.ImageSource = image.createImageSource(buffer); const pixelMap : image.PixelMap = await imageSource.createPixelMap(); if (pixelMap) { pixelMap.getImageInfo((err, imageInfo) => { if (imageInfo) { hilog.info(0x0000, 'testTag', `DemoPushMessageAbility imageInfo: ${imageInfo.size.width} * ${imageInfo.size.height}.`); } }); } // 构建通话详细信息的对象 let callInfo: voipCall.VoipCallAttribute = { callId: callId, voipCallType: voipCall.VoipCallType.VOIP_CALL_VOICE, userName: "name", userProfile: pixelMap, abilityName: 'ability', voipCallState: voipCall.VoipCallState.VOIP_CALL_STATE_DIALING }; // 通知去电消息 let error = await voipCall.reportOutgoingCall(callInfo); if (error != voipCall.ErrorReason.ERROR_NONE) { hilog.error(0x0000, 'testTag', 'Failed to report outgoing call: %{public}d', error); return; } hilog.info(0x0000, 'testTag', 'Get voip message end.'); }); hilog.info(0x0000, 'testTag', 'Succeeded in registering VoIP.'); } }
智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功