mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
BLEScanService: Allow supported ScanSettings on Android API level 23
This commit is contained in:
+24
-3
@@ -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 <https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
package nodomain.freeyourgadget.gadgetbridge.service.btle;
|
package nodomain.freeyourgadget.gadgetbridge.service.btle;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
@@ -17,6 +34,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
@@ -357,11 +375,14 @@ public class BLEScanService extends Service {
|
|||||||
final ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder()
|
final ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder()
|
||||||
.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER); // enforced anyway in background
|
.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
|
scanSettingsBuilder
|
||||||
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
|
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
|
||||||
.setMatchMode(ScanSettings.MATCH_MODE_STICKY)
|
.setMatchMode(ScanSettings.MATCH_MODE_STICKY);
|
||||||
.setLegacy(false);
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
scanSettingsBuilder.setLegacy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner.startScan(scanFilters, scanSettingsBuilder.build(), scanCallback);
|
scanner.startScan(scanFilters, scanSettingsBuilder.build(), scanCallback);
|
||||||
|
|||||||
Reference in New Issue
Block a user