diff --git a/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Adapter.java b/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Adapter.java index e2a4332b..d03c8e21 100644 --- a/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Adapter.java +++ b/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Adapter.java @@ -8,6 +8,7 @@ import android.bluetooth.le.ScanFilter.Builder; import android.bluetooth.le.ScanResult; import android.bluetooth.le.ScanSettings; +import android.os.Build; import android.os.ParcelUuid; import java.util.ArrayList; @@ -35,9 +36,17 @@ public void startScan(ScanFilter filter) { filters.add(new Builder().setServiceUuid(ParcelUuid.fromString(uuid)).build()); } } - ScanSettings settings = new ScanSettings.Builder() - .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) - .build(); + ScanSettings settings; + if (Build.VERSION.SDK_INT >= 26) { + settings = new ScanSettings.Builder() + .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) + .setLegacy(false) + .build(); + } else { + settings = new ScanSettings.Builder() + .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) + .build(); + } BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner(); if (scanner == null) { throw new RuntimeException("No bluetooth scanner available for adapter"); diff --git a/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Peripheral.java b/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Peripheral.java index 160a5de2..256025e4 100644 --- a/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Peripheral.java +++ b/src/droidplug/java/src/main/java/com/nonpolynomial/btleplug/android/impl/Peripheral.java @@ -37,7 +37,7 @@ class Peripheral { private CommandCallback commandCallback; public Peripheral(Adapter adapter, String address) { - this.device = BluetoothAdapter.getAdapter().getRemoteDevice(address); + this.device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address); this.adapter = adapter; this.callback = new Callback(); }