Skip to content

Commit

Permalink
Option to filter by service UUID when starting a scan
Browse files Browse the repository at this point in the history
  • Loading branch information
ulizama committed Aug 19, 2016
1 parent fe751b0 commit ab1a706
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public boolean isSupportBLE(){
}

@Override
public boolean startScan() {
public boolean startScan(UUID[] serviceUUIDs) {
if (!isAvailable() && !isEnabled()){
return false;
}
Expand All @@ -130,12 +130,23 @@ public boolean startScan() {
mLeSettings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.build();
mLeFilters = new ArrayList<ScanFilter>();
mLeFilters = scanFilters(serviceUUIDs);
}
scanLeDevice();
return true;
}

private List<ScanFilter> scanFilters(UUID[] serviceUUIDs) {
List<ScanFilter> list = new ArrayList<>();

for (int i = 0; i <serviceUUIDs.length; i++){
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(serviceUUIDs[i].toStri‌ng())).build();
list.add(filter);
}

return list;
}

private void scanLeDevice(){
mHandler.postDelayed(new Runnable() {
@Override
Expand Down

0 comments on commit ab1a706

Please sign in to comment.