小编Tho*_*s W的帖子

BLE与Android 5.0:如何让设备充当中央和服务器?

我正在使用两个Android 5.0设备通过蓝牙低功耗进行通信,我不想:

  • 设备1充当中央和服务器.

  • 设备2充当外围设备和客户端.


这是我想要实现的行为:

1)设备2开始广告(外围角色).

2)设备1开始扫描(中心角色),并通过ScanCallback的onScanResult方法获取广告设备(BluetoothDevice对象).

3)我现在希望通知广告设备(设备2)它已经被扫描并且能够获得与设备1相关联的蓝牙设备.

4)设备1具有BluetoothGattServer的实例.设备2现在将在设备1上调用connectGatt(上下文上下文,布尔autoConnect,BluetoothGattCallback回调)以获取BluetoothGatt的实例.

5)最后,设备1是服务器,设备2是客户端.


到目前为止,我发现在步骤2中,一旦设备1保持设备2的蓝牙设备,它只能像使用connectGatt的步骤4那样连接客户端.

我可以使用设备1中定义的BluetoothGattServer,并调用:gattServer.connect(BluetoothDevice device,boolean autoConnect),设备为Device 2.

但是如何通知设备2已连接到?

如何将我得到的一个实例BluetoothGatt在设备2,如果我不能叫 connectGatt(上下文,布尔,BluetoothGattCallback)BluetoothDevice类

预先感谢您的帮助 !

一些文件:

BluetoothGattServer

BluetoothDevice类

android bluetooth bluetooth-lowenergy gatt pairing

6
推荐指数
1
解决办法
2071
查看次数

标签 统计

android ×1

bluetooth ×1

bluetooth-lowenergy ×1

gatt ×1

pairing ×1