Skip to content

Commit d294125

Browse files
committed
Add the option to let users define scan filters and scan settings
1 parent 7f8108a commit d294125

File tree

2 files changed

+85
-6
lines changed

2 files changed

+85
-6
lines changed

provisioning/src/main/java/com/espressif/provisioning/ESPProvisionManager.java

+45
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
import android.Manifest;
1818
import android.app.Activity;
1919
import android.bluetooth.BluetoothDevice;
20+
import android.bluetooth.le.ScanFilter;
2021
import android.bluetooth.le.ScanResult;
22+
import android.bluetooth.le.ScanSettings;
2123
import android.content.Context;
2224
import android.os.Build;
2325
import android.os.Handler;
@@ -334,6 +336,49 @@ public void run() {
334336
});
335337
}
336338

339+
/**
340+
* This method is used to scan BLE devices.
341+
*
342+
* @param filters The scan filters that will be used
343+
* @param bleScannerListener BleScanListener for scanning callbacks.
344+
*/
345+
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.BLUETOOTH, Manifest.permission.ACCESS_FINE_LOCATION})
346+
public void searchBleEspDevices(List<ScanFilter> filters, BleScanListener bleScannerListener) {
347+
348+
Log.e(TAG, "Search for BLE devices");
349+
bleScanner = new BleScanner(context, bleScannerListener);
350+
bleScanner.startScan(filters);
351+
}
352+
353+
/**
354+
* This method is used to scan BLE devices.
355+
*
356+
* @param scanSettings The scan settings that will be used
357+
* @param bleScannerListener BleScanListener for scanning callbacks.
358+
*/
359+
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.BLUETOOTH, Manifest.permission.ACCESS_FINE_LOCATION})
360+
public void searchBleEspDevices(ScanSettings scanSettings, BleScanListener bleScannerListener) {
361+
362+
Log.e(TAG, "Search for BLE devices");
363+
bleScanner = new BleScanner(context, bleScannerListener);
364+
bleScanner.startScan(scanSettings);
365+
}
366+
367+
/**
368+
* This method is used to scan BLE devices.
369+
*
370+
* @param filters The scan filters that will be used
371+
* @param scanSettings The scan settings that will be used
372+
* @param bleScannerListener BleScanListener for scanning callbacks.
373+
*/
374+
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH_ADMIN, Manifest.permission.BLUETOOTH, Manifest.permission.ACCESS_FINE_LOCATION})
375+
public void searchBleEspDevices(List<ScanFilter> filters, ScanSettings scanSettings, BleScanListener bleScannerListener) {
376+
377+
Log.e(TAG, "Search for BLE devices");
378+
bleScanner = new BleScanner(context, bleScannerListener);
379+
bleScanner.startScan(filters, scanSettings);
380+
}
381+
337382
/**
338383
* This method is used to scan BLE devices.
339384
*

provisioning/src/main/java/com/espressif/provisioning/device_scanner/BleScanner.java

+40-6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,45 @@ public BleScanner(Context context, String prefix, BleScanListener bleScannerList
7171
*/
7272
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN})
7373
public void startScan() {
74+
List<ScanFilter> filters = new ArrayList<>();
75+
ScanSettings settings = new ScanSettings.Builder()
76+
.setScanMode(ScanSettings.SCAN_MODE_BALANCED)
77+
.build();
78+
startScan(filters, settings);
79+
}
80+
81+
/**
82+
* This method is used to start BLE scan.
83+
*
84+
* @param filters The scan filters that will be used
85+
*/
86+
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN})
87+
public void startScan(List<ScanFilter> filters) {
88+
ScanSettings settings = new ScanSettings.Builder()
89+
.setScanMode(ScanSettings.SCAN_MODE_BALANCED)
90+
.build();
91+
startScan(filters, settings);
92+
}
93+
94+
/**
95+
* This method is used to start BLE scan.
96+
*
97+
* @param scanSettings The scan settings that will be used
98+
*/
99+
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN})
100+
public void startScan(ScanSettings scanSettings) {
101+
List<ScanFilter> filters = new ArrayList<>();
102+
startScan(filters, scanSettings);
103+
}
104+
105+
/**
106+
* This method is used to start BLE scan.
107+
*
108+
* @param filters The scan filters that will be used
109+
* @param scanSettings The scan settings that will be used
110+
*/
111+
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN})
112+
public void startScan(List<ScanFilter> filters, ScanSettings scanSettings) {
74113

75114
if (!bluetoothAdapter.isEnabled()) {
76115
bleScanListener.scanStartFailed();
@@ -79,13 +118,8 @@ public void startScan() {
79118
Log.d(TAG, "Starting BLE device scanning...");
80119

81120
bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();
82-
List<ScanFilter> filters = new ArrayList<>();
83-
ScanSettings settings = new ScanSettings.Builder()
84-
.setScanMode(ScanSettings.SCAN_MODE_BALANCED)
85-
.build();
86-
87121
isScanning = true;
88-
bluetoothLeScanner.startScan(filters, settings, scanCallback);
122+
bluetoothLeScanner.startScan(filters, scanSettings, scanCallback);
89123
handler.postDelayed(stopScanTask, SCAN_TIME_OUT);
90124
}
91125

0 commit comments

Comments
 (0)