BLE connect()到gatt服务器只能使用一个“外围”应用程序,而不能使用我的

时间:2019-04-02 17:27:02

标签: android bluetooth-lowenergy

我正在构建一个Android应用程序以进行BLE付款(非接触式付款)。我要构建两个应用程序:一个将扮演gatt服务器的角色(广告和提供具有特征的服务),另一个用于扫描广告设备,连接到第一个并启动请求。

我的问题是,当我在扫描的设备对象上调用connectGatt时,大约40秒后我收到了STATE_DISCONNECTED和状态133的回调。

我在这个论坛和其他论坛上进行了很多研究,一开始我的难题来自扫描应用程序,所有已知问题(在调用connectGatt()之前添加延迟/在主线程上运行调用...)< / p>

但是最终,我将扫描应用程序与在Play商店中找到的BLE外围设备测试应用程序一起使用,并且在STATE_CONNECTED的回调中运行得很好,并且能够发现服务。

所以我的问题是,为什么其他人无法通过connectGatt访问我的BLE外围应用程序(启动gatt服务器并启动广告)?为何能很好地检测到广告包?我必须精确启动我的gatt服务器时,onServiceAdded回调工作正常。

我如何启动我的gatt服务器:

  public void startGattServer(){
    bluetoothGattServer = bluetoothManager.openGattServer(this, bluetoothGattServerCallback);
    BluetoothGattService service = new BluetoothGattService(UUID.fromString(GattAttributes.APDUSERVICE), BluetoothGattService.SERVICE_TYPE_PRIMARY);
    BluetoothGattCharacteristic apduRequestCharacteristic = new BluetoothGattCharacteristic(
            UUID.fromString(GattAttributes.APDUREQUEST),
            BluetoothGattCharacteristic.PROPERTY_WRITE,
            BluetoothGattCharacteristic.PERMISSION_WRITE);
    BluetoothGattCharacteristic apduResponseCharacteristic = new BluetoothGattCharacteristic(
            UUID.fromString(GattAttributes.APDURESPONSE),
            BluetoothGattCharacteristic.PROPERTY_WRITE,
            BluetoothGattCharacteristic.PERMISSION_WRITE);
    service.addCharacteristic(apduRequestCharacteristic);
    service.addCharacteristic(apduResponseCharacteristic);
    bluetoothGattServer.addService(service);
  }

预先感谢您的回答

0 个答案:

没有答案