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();
}
+1
View File
@@ -336,6 +336,7 @@ limitations under the License.
<string name="sensor_state_power_unit">W</string>
<string name="sensor_could_not_scan">Could not scan for Bluetooth devices (error %1$i).</string>
<string name="bluetooth_disabled">Please enable Bluetooth.</string>
<string name="bluetooth_sensor_summary">%1$s (%2$s)</string>
<string name="settings_open_tracks_summary">All About OpenTracks Project</string>