diff --git a/CHANGES.txt b/CHANGES.txt index 88be936d..f7f1492d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,6 @@ += 1.7.2 = +Android: add isConnectable Property for API26+ (O) #823 (#993) thanks @Gargamil + = 1.7.1 = Android: Add forceScanFilter option for Android (#989, #987) thanks younesspotmaster diff --git a/src/android/BLECentralPlugin.java b/src/android/BLECentralPlugin.java index 08953858..ec755343 100644 --- a/src/android/BLECentralPlugin.java +++ b/src/android/BLECentralPlugin.java @@ -1139,13 +1139,12 @@ public void onScanResult(int callbackType, ScanResult result) { boolean alreadyReported = peripherals.containsKey(address) && !peripherals.get(address).isUnscanned(); if (!alreadyReported) { - - Peripheral peripheral = null; + Boolean isConnectable = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - peripheral = new Peripheral(device, result.getRssi(), result.getScanRecord().getBytes(),result.isConnectable()); - }else{ - peripheral = new Peripheral(device, result.getRssi(), result.getScanRecord().getBytes()); + isConnectable = result.isConnectable(); } + + Peripheral peripheral = new Peripheral(device, result.getRssi(), result.getScanRecord().getBytes(), isConnectable); peripherals.put(device.getAddress(), peripheral); if (discoverCallback != null) { diff --git a/src/android/Peripheral.java b/src/android/Peripheral.java index 46acf821..43cddb5b 100644 --- a/src/android/Peripheral.java +++ b/src/android/Peripheral.java @@ -53,7 +53,7 @@ public class Peripheral extends BluetoothGattCallback { private BluetoothDevice device; private byte[] advertisingData; - private boolean isConnectable = true; + private Boolean isConnectable = null; private int advertisingRSSI; private boolean autoconnect = false; private boolean connected = false; @@ -84,21 +84,13 @@ public Peripheral(BluetoothDevice device) { } - public Peripheral(BluetoothDevice device, int advertisingRSSI, byte[] scanRecord, boolean isConnectable) { + public Peripheral(BluetoothDevice device, int advertisingRSSI, byte[] scanRecord, Boolean isConnectable) { this.device = device; this.advertisingRSSI = advertisingRSSI; this.advertisingData = scanRecord; this.isConnectable = isConnectable; } - public Peripheral(BluetoothDevice device, int advertisingRSSI, byte[] scanRecord) { - - this.device = device; - this.advertisingRSSI = advertisingRSSI; - this.advertisingData = scanRecord; - - } - private void gattConnect() { closeGatt(); @@ -289,8 +281,8 @@ public JSONObject asJSONObject() { json.put("rssi", advertisingRSSI); } - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - json.put("connectable", this.isConnectable); + if (this.isConnectable != null) { + json.put("connectable", this.isConnectable.booleanValue()); } } catch (JSONException e) { // this shouldn't happen e.printStackTrace(); diff --git a/types.d.ts b/types.d.ts index 18a33985..0df93509 100644 --- a/types.d.ts +++ b/types.d.ts @@ -14,6 +14,8 @@ declare namespace BLECentralPlugin { id: string; rssi: number; advertising: ArrayBuffer | any; + /* Android only */ + connectable?: boolean; state: PeripheralState; }