Tôi đang cố gắng đọc các đặc tính từ thiết bị BLE liên tục.Android Bluetooth LE - Đọc các đặc điểm không hoạt động trên Samsung
tôi đã tạo ra một Runnable trong lớp dịch vụ của tôi:
private class BackgroundRunnableForRead implements Runnable
{
private volatile boolean isRunning = true ;
@Override
public void run() {
try {
BluetoothLeService.this.backgroundRunID = Thread.currentThread().getId();
while(isRunning) {
List<BluetoothGattService> gattServices = BluetoothLeService.this.getSupportedGattServices();
if (gattServices != null && gattServices.size() > 0) {
BluetoothGattCharacteristic characteristic = getCharacteristic(gattServices);
if (characteristic != null && (characteristic.getProperties() & 2) > 0) {
BluetoothLeService.this.readCharacteristic(characteristic);
}
}
}
}
catch(Exception e)
{
isRunning= false;
e.printStackTrace();
}
}
public void kill()
{
this.isRunning = false;
}
}
Và trên khám phá thành công của dịch vụ tôi đang kêu gọi:
public void startReadingCharacteristics()
{
System.out.println("BluetoothLeService.startReadingCharacteristics");
this.mBackgroundRunnable = new BackgroundRunnableForRead();
mReadThread = new Thread(mBackgroundRunnable);
mReadThread.start();
}
Và đây là của tôi trên tính trạng đọc callback -
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
int status) {
System.out.println("BluetoothLeService.onCharacteristicRead" + status);
if (status == BluetoothGatt.GATT_SUCCESS) {
broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
}
}
Ứng dụng hoạt động tốt trên Nexus 5, Nexus 4 và Motorola G.
Khi tôi đang chạy mã này trên Samsung S6 nó không hoạt động, onCharacteristicRead()
không được gọi.
Tôi đọc rằng việc thực hiện các cuộc gọi tuần tự đến readCharacteristics()
có thể gây ra sự cố khi nó chờ onCharacteristicRead thực thi.
Phiên bản hệ điều hành là gì? –
Phiên bản Os - Android 5.1.1. – Anukool
Vui lòng định dạng mã của bạn –