Почему мой OnCharacteristicChanged не срабатывает?Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Почему мой OnCharacteristicChanged не срабатывает?

Сообщение Anonymous »

Проблема в том, «как мой код не может вызвать OnCharacteristicChanged... я установил для уведомления значение true, и единственный результат, который у меня есть, это:

Подключено к серверу GATT.

Сервис: android.bluetooth.BluetoothGattService@bf8aa7

Qui entra, service not nullo

Найдено свойство: 00005303-0000-0041-4c50-574953450000

Характеристика поддерживает уведомления.

Найдено характеристика: 00005302-0000-0041-4c50-574953450000

Характеристика НЕ ​​поддерживает уведомления или индикации.

Характеристика найденных и установленных уведомлений.

Дескриптор уведомления, записанного успешно.

onDescriptorWrite :Sucess

Отключено от сервера GATT, статус: 8
это мой код:

Код: Выделить всё

public CompletableFuture connect(String deviceAddress)
{
CompletableFuture future = new CompletableFuture();

BluetoothManager bluetoothManager = getSystemService(BluetoothManager.class);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
device = bluetoothAdapter.getRemoteDevice(deviceAddress);

gatt = device.connectGatt(null, false, new BluetoothGattCallback()
{
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
{
if (newState == BluetoothGatt.STATE_CONNECTED) {
BA.Log("Connected to GATT server.");
gatt.discoverServices();
} else if (newState == BluetoothGatt.STATE_DISCONNECTED) {
BA.Log("Disconnected from GATT server, status: " + status);
future.complete(null);
}
}

@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status)
{
if (status == BluetoothGatt.GATT_SUCCESS) {
BluetoothGattService service = gatt.getService(UUID.fromString(SERVICE_UUID));
BA.Log("Service : " + service);
//attualmente stampa Service : android.bluetooth.BluetoothGattService@bf8aa7  con 00005303-0000-0041-4c50-574953450000
//attualmente stampa Service : android.bluetooth.BluetoothGattService@ad02a43 con 00002902-0000-1000-8000-00805f9b34fb
if (service != null)
{
BA.Log("Qui entra, service non nullo");

BluetoothGattCharacteristic characteristic = service.getCharacteristic(UUID.fromString(CHARACTERISTIC_UUID_NOTIFY));
if (characteristic != null)
{
gatt.setCharacteristicNotification(characteristic, true);
startReadBlock = true;
BA.Log("Characteristic for notifications found and notifications set.");

//Before onCharacteristicChanged is called you had to enable notification.  Someting like:
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(descriptor);
BA.Log("Descriptor for notification written successfully.");

}else
{
BA.Log("Notification characteristic not found.");
}
}
}
}

@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)
{
byte[] data = characteristic.getValue();
BA.Log("Received HandleRX: " + bytesToHex(data));
if (startReadBlock)
{
BA.Log("START READDATABLOCK");
readDataBlock(data);
}
}

@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
BA.Log("Characteristic written successfully.");
} else {
BA.Log("Error writing characteristic: " + status);
}
}

@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
super.onDescriptorWrite(gatt, descriptor, status);
BA.Log("onDescriptorWrite :" + ((status == BluetoothGatt.GATT_SUCCESS) ? "Sucess" : "false"));
}
});

return future;
}
я остаюсь на час, чтобы добавить журнал попыток выполнить код, но ничего....это дни, когда я сталкиваюсь с этой проблемой

Подробнее здесь: https://stackoverflow.com/questions/790 ... -triggered
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»