diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothFactory.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothFactory.java index abe3ad66..8028e5c3 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothFactory.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothFactory.java @@ -17,6 +17,7 @@ package com.health.openscale.core.bluetooth; import android.content.Context; +import android.util.SparseArray; import java.util.Locale; @@ -118,7 +119,7 @@ public class BluetoothFactory { if (deviceName.equals("ADV") || deviceName.equals("Chipsea-BLE")) { return new BluetoothOKOK(context); } - if (deviceName.isEmpty()) { + if (deviceName.equals("NoName OkOk")) { return new BluetoothOKOK2(context); } if (deviceName.equals("BF105") || deviceName.equals("BF720")) { @@ -150,4 +151,11 @@ public class BluetoothFactory { } return null; } + + public static String convertNoNameToDeviceName(SparseArray manufacturerSpecificData) { + String deviceName = null; + deviceName = BluetoothOKOK2.convertNoNameToDeviceName(manufacturerSpecificData); + + return deviceName; + } } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOKOK2.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOKOK2.java index 71a71f99..7a131b57 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOKOK2.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOKOK2.java @@ -15,6 +15,9 @@ */ package com.health.openscale.core.bluetooth; +import static com.health.openscale.core.utils.Converters.WeightUnit.LB; +import static com.health.openscale.core.utils.Converters.WeightUnit.ST; + import android.bluetooth.le.ScanFilter; import android.bluetooth.le.ScanResult; import android.content.Context; @@ -35,9 +38,6 @@ import java.util.List; import timber.log.Timber; -import static com.health.openscale.core.utils.Converters.WeightUnit.LB; -import static com.health.openscale.core.utils.Converters.WeightUnit.ST; - public class BluetoothOKOK2 extends BluetoothCommunication { private static final int IDX_WEIGHT_MSB = 0; private static final int IDX_WEIGHT_LSB = 1; @@ -66,6 +66,21 @@ public class BluetoothOKOK2 extends BluetoothCommunication { central = new BluetoothCentralManager(context, btCallback, new Handler(Looper.getMainLooper())); } + static String convertNoNameToDeviceName(SparseArray manufacturerSpecificData) { + int vendorIndex = -1; + for (int i = 0; i < manufacturerSpecificData.size(); i++) { + int vendorId = manufacturerSpecificData.keyAt(i); + if ((vendorId & 0xff) == 0xc0) { // 0x00c0-->0xffc0 + vendorIndex = vendorId; + } + } + if (vendorIndex == -1) { + return null; + } + + return "NoName OkOk"; + } + private final BluetoothCentralManagerCallback btCallback = new BluetoothCentralManagerCallback() { @Override public void onDiscoveredPeripheral(@NotNull BluetoothPeripheral peripheral, @NotNull ScanResult scanResult) { diff --git a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java index 90cbcad4..7bea7c1c 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java @@ -325,8 +325,12 @@ public class BluetoothSettingsFragment extends Fragment { BluetoothDeviceView deviceView = new BluetoothDeviceView(context); deviceView.setDeviceName(formatDeviceName(bleScanResult.getDevice())); - String name = device.getName() != null ? device.getName() : ""; - BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(context, name); + String deviceName = device.getName(); + if (deviceName == null) { + deviceName = BluetoothFactory.convertNoNameToDeviceName(bleScanResult.getScanRecord().getManufacturerSpecificData()); + } + + BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(context, deviceName); if (btDevice != null) { Timber.d("Found supported device %s (driver: %s)", formatDeviceName(device), btDevice.driverName());