Skip to content

Commit 912ce83

Browse files
committed
Add connectable flag to type definitions
* Reduce version branching slightly by using nullable
1 parent 8b826e1 commit 912ce83

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
= 1.7.2 =
2+
Android: add isConnectable Property for API26+ (O) #823 (#993) thanks @Gargamil
3+
14
= 1.7.1 =
25
Android: Add forceScanFilter option for Android (#989, #987) thanks younesspotmaster
36

src/android/BLECentralPlugin.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,13 +1139,12 @@ public void onScanResult(int callbackType, ScanResult result) {
11391139
boolean alreadyReported = peripherals.containsKey(address) && !peripherals.get(address).isUnscanned();
11401140

11411141
if (!alreadyReported) {
1142-
1143-
Peripheral peripheral = null;
1142+
Boolean isConnectable = null;
11441143
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
1145-
peripheral = new Peripheral(device, result.getRssi(), result.getScanRecord().getBytes(),result.isConnectable());
1146-
}else{
1147-
peripheral = new Peripheral(device, result.getRssi(), result.getScanRecord().getBytes());
1144+
isConnectable = result.isConnectable();
11481145
}
1146+
1147+
Peripheral peripheral = new Peripheral(device, result.getRssi(), result.getScanRecord().getBytes(), isConnectable);
11491148
peripherals.put(device.getAddress(), peripheral);
11501149

11511150
if (discoverCallback != null) {

src/android/Peripheral.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class Peripheral extends BluetoothGattCallback {
5353

5454
private BluetoothDevice device;
5555
private byte[] advertisingData;
56-
private boolean isConnectable = true;
56+
private Boolean isConnectable = null;
5757
private int advertisingRSSI;
5858
private boolean autoconnect = false;
5959
private boolean connected = false;
@@ -84,21 +84,13 @@ public Peripheral(BluetoothDevice device) {
8484

8585
}
8686

87-
public Peripheral(BluetoothDevice device, int advertisingRSSI, byte[] scanRecord, boolean isConnectable) {
87+
public Peripheral(BluetoothDevice device, int advertisingRSSI, byte[] scanRecord, Boolean isConnectable) {
8888
this.device = device;
8989
this.advertisingRSSI = advertisingRSSI;
9090
this.advertisingData = scanRecord;
9191
this.isConnectable = isConnectable;
9292
}
9393

94-
public Peripheral(BluetoothDevice device, int advertisingRSSI, byte[] scanRecord) {
95-
96-
this.device = device;
97-
this.advertisingRSSI = advertisingRSSI;
98-
this.advertisingData = scanRecord;
99-
100-
}
101-
10294
private void gattConnect() {
10395

10496
closeGatt();
@@ -289,8 +281,8 @@ public JSONObject asJSONObject() {
289281
json.put("rssi", advertisingRSSI);
290282
}
291283

292-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
293-
json.put("connectable", this.isConnectable);
284+
if (this.isConnectable != null) {
285+
json.put("connectable", this.isConnectable.booleanValue());
294286
}
295287
} catch (JSONException e) { // this shouldn't happen
296288
e.printStackTrace();

types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ declare namespace BLECentralPlugin {
1414
id: string;
1515
rssi: number;
1616
advertising: ArrayBuffer | any;
17+
/* Android only */
18+
connectable?: boolean;
1719
state: PeripheralState;
1820
}
1921

0 commit comments

Comments
 (0)