通过阅读本文,您可以了解 鸿蒙端集成SDK的方法。
环境要求
鸿蒙端具体环境要求,更多信息,请参见使用限制。
集成SDK
方法一:ohpm 集成(推荐)
在根目录的oh-package.json5中添加SDK dependencies:
{ "name": "demo", "version": "1.0.0", "description": "Please describe the basic information.", "main": "", "author": "", "license": "", "dependencies": { "@dingrtc/dingrtc": "3.5.0", } }
说明此处ohpm 依赖的版本仅供参考,获取最新的ohpm依赖,请参见 SDK下载
在app/src/main/module.json5文件中添加如下代码,获取相应的设备权限。
{ "module": { "name": "Demo", "type": "entry", "description": "$string:module_desc", "mainElement": "DemoAbility", "deviceTypes": [ "phone", "tablet", "2in1" ], "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", "abilities": [ { "name": "DemoAbility", "srcEntry": "./ets/demoability/DemoAbility.ets", "description": "$string:DemoAbility_desc", "icon": "$media:layered_image", "label": "$string:DemoAbility_label", "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", "exported": true, "backgroundModes": [ "audioRecording", "audioPlayback", "dataTransfer" ], "skills": [ { "entities": [ "entity.system.home" ], "actions": [ "action.system.home" ] } ] } ], "requestPermissions": [ { "name": "ohos.permission.INTERNET" // 使用网络权限 }, { "name": "ohos.permission.GET_WIFI_INFO" // 获取WLAN信息权限 }, { "name": "ohos.permission.GET_NETWORK_INFO" // 获取网络状态权限 }, { "name": "ohos.permission.KEEP_BACKGROUND_RUNNING" // Demo 长时任务权限,用于后台音频采集和播放 }, { "name": "ohos.permission.MICROPHONE", "reason": "$string:microphone", "usedScene": { "abilities": [ "DemoAbility" ], "when": "inuse" } }, { "name": "ohos.permission.CAMERA", "reason": "$string:camera", "usedScene": { "abilities": [ "DemoAbility" ], "when": "inuse" } }, ], } }
RTC业务一般需要开启长时任务以便于应用退到后台后也可以保持通话。
开启长时服务请参考:上述json 中的backgroundModes 以及鸿蒙官方文档-长时任务
方法二:手动集成
下载并解压OHOS SDK,下载地址,请参见SDK下载。
复制SDK文件dingrtc.har到App模块下的libs文件夹中。
{ "name": "demo", "version": "1.0.0", "description": "Please describe the basic information.", "main": "", "author": "", "license": "", "dependencies": { "@dingrtc/dingrtc": "file:./src/main/libs/dingrtc.har", } }
后续步骤
完成集成SDK操作后,您可以实现音视频通信的基本功能。具体操作,请参见 Ohos 基本功能。
文档内容是否对您有帮助?