From 3f6a4975fa5a4ce8abd58a3a15271b201c715426 Mon Sep 17 00:00:00 2001 From: stickflowerfightclub Date: Sun, 12 Apr 2026 10:27:19 +0200 Subject: [PATCH] Fix: Allow selection of internal sensors when Bluetooth is disabled --- .../BluetoothLeSensorPreference.java | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/settings/bluetooth/BluetoothLeSensorPreference.java b/src/main/java/de/dennisguse/opentracks/settings/bluetooth/BluetoothLeSensorPreference.java index 7e90f94d9..4eef96022 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/bluetooth/BluetoothLeSensorPreference.java +++ b/src/main/java/de/dennisguse/opentracks/settings/bluetooth/BluetoothLeSensorPreference.java @@ -191,26 +191,6 @@ public abstract class BluetoothLeSensorPreference extends DialogPreference { List serviceUUIDs = getArguments().getParcelableArrayList(ARG_BLE_SERVICE_UUIDS); boolean includeInternalSensor = getArguments().getBoolean(ARG_INCLUDE_INTERNAL); - BluetoothAdapter bluetoothAdapter = BluetoothUtils.getAdapter(getContext()); - if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { - Log.w(TAG, "Bluetooth adapter is present or not enabled."); - Toast.makeText(getContext(), R.string.bluetooth_disabled, Toast.LENGTH_SHORT).show(); - dismiss(); - return; - } - - if (bluetoothAdapter.isDiscovering()) { - Log.i(TAG, "Cancelling ongoing Bluetooth discovery."); - bluetoothAdapter.cancelDiscovery(); - } - - scanner = bluetoothAdapter.getBluetoothLeScanner(); - if (scanner == null) { - Log.e(TAG, "BluetoothLeScanner is null."); - dismiss(); - return; - } - listAdapter.add(SensorType.NONE.getPreferenceValue(), getContext().getString(DEVICE_NONE_RESOURCEID)); selectedEntryIndex = 0; @@ -228,6 +208,28 @@ public abstract class BluetoothLeSensorPreference extends DialogPreference { selectedEntryIndex = !includeInternalSensor ? 1 : 2; } + BluetoothAdapter bluetoothAdapter = BluetoothUtils.getAdapter(getContext()); + if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { + Log.w(TAG, "Bluetooth adapter is present or not enabled. Skipping BLE scan."); + Toast.makeText(getContext(), R.string.bluetooth_disabled, Toast.LENGTH_SHORT).show(); + if (!includeInternalSensor) { + dismiss(); + } + return; + } + + if (bluetoothAdapter.isDiscovering()) { + Log.i(TAG, "Cancelling ongoing Bluetooth discovery."); + bluetoothAdapter.cancelDiscovery(); + } + + scanner = bluetoothAdapter.getBluetoothLeScanner(); + if (scanner == null) { + Log.e(TAG, "BluetoothLeScanner is null."); + dismiss(); + return; + } + List scanFilter = null; if (PreferencesUtils.getBluetoothFilterEnabled()) { scanFilter = serviceUUIDs.stream()