代码拉取完成,页面将自动刷新
同步操作将从 OpenHarmony-SIG/ohos-beacon-library 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
蓝牙工具,主要涉及信标区域监控以及信标设备测距
npm install @ohos/ohos_beacon_library --save
OpenHarmony npm环境配置等更多内容,请参考 如何安装OpenHarmony npm包 。
1.在page页面中引入信标库必要的文件
import { Identifier, Region, BeaconParser, BeaconManager, RangeNotifier,Beacon } from '@ohos/ohos_beacon_library'
import bluetooth from '@ohos.bluetooth';
2.使用
- 启动测距
_this.beaconManager.addRangeNotifier(new class implements RangeNotifier {
didRangeBeaconsInRegion(beacons: Array<Beacon>, region: Region): void {
_this.beaconList = beacons
}
});
_this.beaconManager.startRangingBeacons(region);
- 停止测距
this.beaconManager.stopRangingBeacons(new Region("myRangingUniqueId", null, null, null));
- 启动监控
_this.beaconManager.addMonitorNotifier(new class implements MonitorNotifier {
INSIDE:number = 1
OUTSIDE:number = 0
didEnterRegion(region:Region):void {
_this.enterRegionText = "I just saw a region: " + region.getUniqueId()
}
didExitRegion(region:Region):void {
_this.enterRegionText = "I no longer see an beacon in Region:" + region.getUniqueId()
}
didDetermineStateForRegion(state:number, region:Region):void {
_this.determineStateText = "I have just switched from seeing/not seeing beacons: " + state
}
});
_this.beaconManager.startMonitoring(region);
- 停止监控
this.beaconManager.stopMonitoring(new Region("myMonitorUniqueId", null, null, null));
@State private beaconManager: BeaconManager = BeaconManager.getInstanceForApplication()
.beaconManager.addMonitorNotifier(notifier:MonitorNotifier): void
.beaconManager.startMonitoring(region:Region ):void
.beaconManager.addRangeNotifier(notifier:RangeNotifier):void
.beaconManager.startRangingBeacons(region:Region):void
new BeaconParser().setBeaconLayout(beaconLayout:String):void
Identifier.parse(stringValue:String, desiredByteLength?:number):Identifier
Region(uniqueId: string, id1?: Identifier, id2?: Identifier, id3?: Identifier, identifiers?: Array<Identifier>, bluetoothAddress?: string)
支持 OpenHarmony API version 8 及以上版本。
|---- ohos_beacon_library
| |---- entry # 示例代码文件夹
| |---- ohos_beacon_library # beacon库
| |----src
| |----main
| |----ets
| |----components
| |---- beaconLibrary # beacon库文件夹
| |---- client #客户端三种情况数据处理
| |---- distance 设备相关设置及距离配置逻辑
| |---- logging #日志相关逻辑
| |---- service #服务端处理逻辑
| |---- simulator #信标计算
| |---- startup #数据发送与接收
| |---- utils #工具类
| |---- AltBeacon.ets #建立信标通信
| |---- BeaconParser.ets #beacon数据包解析
| |---- bluetooth # 蓝牙库
| |---- BleAdvertisement.ets #信标广播逻辑
| |---- Pdu.ets #蓝牙数据传递单元
| |---- README.md # 安装使用方法
使用过程中发现任何问题都可以提 Issue 给我们,当然,我们也非常欢迎你给我们发 PR 。
本项目基于 Apache License 2.0 ,请自由地享受和参与开源。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。