From 3c64530ed80d897f9337696aa4347b87850f945b Mon Sep 17 00:00:00 2001 From: OliE Date: Thu, 16 Mar 2017 17:03:10 +0100 Subject: [PATCH] fix bluetooth mi scale bug if no device is in range --- android_app/app/build.gradle | 2 +- .../openscale/core/BluetoothMiScale.java | 21 ++++++++++--------- .../res/layout-large/fragment_overview.xml | 3 ++- .../src/main/res/layout/fragment_overview.xml | 3 ++- .../src/main/res/values/type_btdevices.xml | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/android_app/app/build.gradle b/android_app/app/build.gradle index 3ee3cba3..62b9745f 100644 --- a/android_app/app/build.gradle +++ b/android_app/app/build.gradle @@ -8,7 +8,7 @@ android { applicationId "com.health.openscale" minSdkVersion 18 targetSdkVersion 22 // don't set target sdk > 22 otherwise bluetooth le discovery need permission to ACCESS_COARSE_LOCATION - versionCode 11 + versionCode 12 versionName "1.4.3" } diff --git a/android_app/app/src/main/java/com/health/openscale/core/BluetoothMiScale.java b/android_app/app/src/main/java/com/health/openscale/core/BluetoothMiScale.java index 61e47aab..43f2fa10 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/BluetoothMiScale.java +++ b/android_app/app/src/main/java/com/health/openscale/core/BluetoothMiScale.java @@ -67,21 +67,22 @@ public class BluetoothMiScale extends BluetoothCommunication { scanCallback = new BluetoothAdapter.LeScanCallback() { @Override - public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) - { - if (device.getName().equals(btDeviceName)) { - Log.d("BluetoothMiScale", "Mi Scale found trying to connect..."); + public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) { + if (device.getAddress().replace(":", "").toUpperCase().startsWith("880F10") || + device.getAddress().replace(":", "").toUpperCase().startsWith("C80F10") ) // Xiaomi + { + if (device.getName().equals(btDeviceName)) { + Log.d("BluetoothMiScale", "Mi Scale found trying to connect..."); - if (scanRecord.length > 30) { final byte[] weightData = Arrays.copyOfRange(scanRecord, 21, 31); weightData[0] = 0x62; // Set weight remove to false to come through parse bytes parseBytes(weightData); + + bluetoothGatt = device.connectGatt(context, false, gattCallback); + + searchHandler.removeCallbacksAndMessages(null); + btAdapter.stopLeScan(scanCallback); } - - bluetoothGatt = device.connectGatt(context, false, gattCallback); - - searchHandler.removeCallbacksAndMessages(null); - btAdapter.stopLeScan(scanCallback); } } }; diff --git a/android_app/app/src/main/res/layout-large/fragment_overview.xml b/android_app/app/src/main/res/layout-large/fragment_overview.xml index 5a0db054..9b279591 100644 --- a/android_app/app/src/main/res/layout-large/fragment_overview.xml +++ b/android_app/app/src/main/res/layout-large/fragment_overview.xml @@ -88,7 +88,8 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="90" - android:stretchColumns="1"> + android:stretchColumns="1" + android:id="@+id/tableLayoutMeasurements"> + android:stretchColumns="1" + android:id="@+id/tableLayoutMeasurements"> - Xiaomi Mi Scale + Xiaomi Mi Scale v1 openScale Custom Scale