无法检测的BLE GATT服务器Nexus 9

时间:2015-09-02 11:09:08

标签: android bluetooth server gatt

我正在开发一个蓝牙聊天应用程序。我在我的应用程序中使用BluetoothLE。我在Nexus 9上打开GATT服务器,但其他设备找不到我。但是,如果我尝试将设备直接连接到connect("B4:CE:F6:B6:75:16")连接。

这是我启动服务器的方法:

private void createServiceWithCharacteristics() {
if (bluetoothLeAdvertiser != null && bluetoothAdapter != null) {

    mGattServer = bluetoothManager.openGattServer(this, mGattServerCallback);

    BluetoothGattService ias = new BluetoothGattService(
            GattAttributes.getServiceUuid(),
            BluetoothGattService.SERVICE_TYPE_PRIMARY);

    notifyCharacteristic = new BluetoothGattCharacteristic(
            UUID.fromString(GattAttributes.CHARACTERISTIC_BLUETOOTH_APP_MESSAGE_NOTIFY),
            BluetoothGattCharacteristic.PROPERTY_NOTIFY,
            BluetoothGattCharacteristic.PERMISSION_READ);
    notifyCharacteristic.addDescriptor(new BluetoothGattDescriptor(GattAttributes.CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID,
            BluetoothGattCharacteristic.PERMISSION_WRITE));

    messageCharacteristic = new BluetoothGattCharacteristic(
            UUID.fromString(GattAttributes.CHARACTERISTIC_BLUETOOTH_APP_MESSAGE_READ),
            BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE,
            BluetoothGattCharacteristic.PERMISSION_WRITE);
    messageCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);

    connectionExtendedCharacteristic = new BluetoothGattCharacteristic(
            UUID.fromString(GattAttributes.CHARACTERISTIC_BLUETOOTH_APP_IS_CONNECTION_EXTENDED),
            BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE,
            BluetoothGattCharacteristic.PERMISSION_WRITE);
    connectionExtendedCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);

    ias.addCharacteristic(notifyCharacteristic);
    ias.addCharacteristic(messageCharacteristic);
    ias.addCharacteristic(connectionExtendedCharacteristic);
    mGattServer.addService(ias);
}

}

0 个答案:

没有答案