Skip to content

Commit

Permalink
Update BleManager.java
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosinigaglia committed Sep 27, 2019
1 parent 176cab4 commit 11defb9
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions android/src/main/java/it/innove/BleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,12 @@ private Peripheral savePeripheral(BluetoothDevice device) {
String address = device.getAddress();
synchronized (peripherals) {
if (!peripherals.containsKey(address)) {
Peripheral peripheral = new Peripheral(device, reactContext);
Peripheral peripheral;
if (Build.VERSION.SDK_INT >= LOLLIPOP && !forceLegacy) {
peripheral = new LollipopPeripheral(device, reactContext);
} else {
peripheral = new Peripheral(device, reactContext);
}
peripherals.put(device.getAddress(), peripheral);
}
}
Expand Down Expand Up @@ -473,7 +478,12 @@ public void onReceive(Context context, Intent intent) {
}

if (bondState == BluetoothDevice.BOND_BONDED) {
Peripheral peripheral = new Peripheral(device, reactContext);
Peripheral peripheral;
if (Build.VERSION.SDK_INT >= LOLLIPOP && !forceLegacy) {
peripheral = new LollipopPeripheral(device, reactContext);
} else {
peripheral = new Peripheral(device, reactContext);
}
WritableMap map = peripheral.asWritableMap();
sendEvent("BleManagerPeripheralDidBond", map);
}
Expand Down Expand Up @@ -546,7 +556,12 @@ public void getBondedPeripherals(Callback callback) {
WritableArray map = Arguments.createArray();
Set<BluetoothDevice> deviceSet = getBluetoothAdapter().getBondedDevices();
for (BluetoothDevice device : deviceSet) {
Peripheral peripheral = new Peripheral(device, reactContext);
Peripheral peripheral;
if (Build.VERSION.SDK_INT >= LOLLIPOP && !forceLegacy) {
peripheral = new LollipopPeripheral(device, reactContext);
} else {
peripheral = new Peripheral(device, reactContext);
}
WritableMap jsonBundle = peripheral.asWritableMap();
map.pushMap(jsonBundle);
}
Expand Down

0 comments on commit 11defb9

Please sign in to comment.