代码拉取完成,页面将自动刷新
本示例通过使用蓝牙低功耗心率服务,展示蓝牙相关API用法。实现了以下几点功能:
相关概念
搜索设备 | 搜索结果 |
---|---|
连接成功 | 实时心率 |
---|---|
使用说明
entry/src/main/ets/
|---constants
| |---BleConstants.ts // BLE常量
| |---StyleConstants.ts // Style样式常量
|---entryability
|---model
| |---BluetoothDevice.ets // 蓝牙设备model
|---pages
| |---Main.ets // 首页
| |---HeartRate.ets // 实时心率图
|---uicomponents
| |---HeartRateGraph.ets // 实时心率图表
| |---NavigationBar.ets // 顶部导航栏
|---uitls
| |---ArrayBufferUtils.ts // ArrayBuffer工具
| |---DateUtils.ts // 日期工具
| |---Log.ts // 日志工具
|---viewmodel
| |---BluetoothViewModel.ets // 主要封装了蓝牙库相关的接口,实现相关功能,如:开启蓝牙、扫描BLE、连接、断连等功能
advertiser/src/main/ets/
|---constants
| |---BleConstants.ts // BLE常量
|---entryability
|---pages
| |---Main.ets // 首页
|---uitls
| |---ArrayBufferUtils.ts // ArrayBuffer工具
| |---Log.ts // 日志工具
| |---MathUtils.ts // Math工具,用于生成随机数
|---viewmodel
| |---AdvertiserBluetoothViewModel.ets // 主要封装了蓝牙库相关的接口,实现相关功能,如:开启蓝牙、开启蓝牙心率广播等功能
权限名 | 权限说明 | 级别 |
---|---|---|
ohos.permission.USE_BLUETOOTH | 允许应用查看蓝牙的配置。 | normal |
ohos.permission.DISCOVER_BLUETOOTH | 允许应用配置本地蓝牙,查找远端设备且与之配对连接。 | normal |
ohos.permission.MANAGE_BLUETOOTH | 允许应用配对蓝牙设备,并对设备的电话簿或消息进行访问。 | system_basic |
ohos.permission.APPROXIMATELY_LOCATION | 允许应用获取设备模糊位置信息。 | normal |
ohos.permission.LOCATION | 允许应用获取设备位置信息。 | normal |
ohos.permission.ACCESS_BLUETOOTH | 允许应用接入蓝牙并使用蓝牙能力,例如配对、连接外围设备等。 | normal |
本示例需要使用设备来模拟BLE心率设备。这里使用OpenHarmony来模拟了BLE心率设备,相关代码在module - advertiser
。使用另一台OpenHarmony设备运行advertiser
编译出来的hap后,点击开启BLE心率广播
。当BLE心率服务应用扫描并连接到模拟的BLE心率设备后,就可以在应用中查看当前模拟的实时心率。
如需单独下载本工程,执行如下命令:
git init
git config core.sparsecheckout true
echo code/BasicFeature/Connectivity/Bluetooth/ > .git/info/sparse-checkout
git remote add origin https://gitee.com/openharmony/applications_app_samples.git
git pull origin master
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。