BLEデバイスから特性を連続的に読み取ろうとしています。Android Bluetooth LE - 読み取り特性がSamsungで動作しない
私は私のサービス・クラスでのRunnableを作成しました:
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;
}
}
と私は呼び出していたサービスの成功の発見について:
public void startReadingCharacteristics()
{
System.out.println("BluetoothLeService.startReadingCharacteristics");
this.mBackgroundRunnable = new BackgroundRunnableForRead();
mReadThread = new Thread(mBackgroundRunnable);
mReadThread.start();
}
そして、これは、コールバック読んcharactericsに私である -
を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);
}
}
アプリケーションは、Nexus 5、Nexus 4、Motorola Gで正常に動作します。
私はこのコードをSamsung S6で実行しても機能しません。onCharacteristicRead()
は呼び出されません。
readCharacteristics()
を呼び出すと、onCharacteristicReadが実行されるのを待つときに問題が発生することがあります。
OSのバージョンとは何ですか? –
Osバージョン - Android 5.1.1。 – Anukool
コードを書式化してください –