Bluetooth sensor settings: show sensor name in addition (if cached via Android OS).

Fixes #508.
This commit is contained in:
Dennis Guse
2023-12-27 11:32:56 +01:00
parent eaad33c23b
commit 1bd75754e4
2 changed files with 14 additions and 0 deletions
@@ -1,6 +1,8 @@
package de.dennisguse.opentracks.settings.bluetooth;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanFilter;
@@ -35,6 +37,7 @@ import de.dennisguse.opentracks.util.PermissionRequester;
* Preference to select a discoverable Bluetooth LE device.
* Based upon ListPreference.
*/
@SuppressLint("MissingPermission")
public abstract class BluetoothLeSensorPreference extends DialogPreference {
private static final String TAG = BluetoothLeSensorPreference.class.getSimpleName();
@@ -89,6 +92,16 @@ public abstract class BluetoothLeSensorPreference extends DialogPreference {
return getContext().getString(DEVICE_NONE_RESOURCEID);
}
BluetoothAdapter bluetoothAdapter = BluetoothUtils.getAdapter(getContext());
if (bluetoothAdapter == null) {
Log.w(TAG, "No Bluetooth adapter present");
return getValue();
}
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(getValue());
if (device != null && device.getName() != null) {
return getContext().getString(R.string.bluetooth_sensor_summary, device.getAddress(), device.getName());
}
return getValue();
}