diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLEScanService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLEScanService.java index 9b9acab17..56bedcdfb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLEScanService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/BLEScanService.java @@ -1,3 +1,20 @@ +/* Copyright (C) 2024 Daniel Dakhno, José Rebelo, Andreas Shimokawa + + This file is part of Gadgetbridge. + + Gadgetbridge is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Gadgetbridge is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . */ + package nodomain.freeyourgadget.gadgetbridge.service.btle; import android.Manifest; @@ -17,6 +34,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; +import android.os.Build; import android.os.Handler; import android.os.IBinder; @@ -357,11 +375,14 @@ public class BLEScanService extends Service { final ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_POWER); // enforced anyway in background - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { scanSettingsBuilder .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) - .setMatchMode(ScanSettings.MATCH_MODE_STICKY) - .setLegacy(false); + .setMatchMode(ScanSettings.MATCH_MODE_STICKY); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + scanSettingsBuilder.setLegacy(false); } scanner.startScan(scanFilters, scanSettingsBuilder.build(), scanCallback);