Browse Source

Bumped to v37, fixed startup crash for BLE

Info @ meCoffee 5 years ago
parent
commit
7dfb9a6a91
2 changed files with 13 additions and 10 deletions
  1. 2 2
      AndroidManifest.xml
  2. 11 8
      src/nl/digitalthings/mebarista/BLEHandler.java

+ 2 - 2
AndroidManifest.xml

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="nl.digitalthings.mebarista"
-    android:versionCode="36"
-    android:versionName="v7.beta36" >
+    android:versionCode="37"
+    android:versionName="v7.beta37" >
 
     <uses-sdk
         android:minSdkVersion="11"

+ 11 - 8
src/nl/digitalthings/mebarista/BLEHandler.java

@@ -140,7 +140,7 @@ public class BLEHandler {
         @Override
         public void handleMessage( Message msg ) {
 
-            if( characteristic == null )
+            if( characteristic == null || mBluetoothGatt == null )
                 return;
 
             characteristic.setValue( ( byte[] ) msg.obj );
@@ -457,14 +457,8 @@ public class BLEHandler {
         if( mBluetoothAdapter == null )
             mBluetoothAdapter = btmanager.getAdapter(); // BluetoothAdapter.getDefaultAdapter();
 
-        if( false ) {
-        /* BluetoothAdapter */
 
 
-            // mBluetoothAdapter.startDiscovery();
-            mBluetoothAdapter.startLeScan(new UUID[]{UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb")}, mLeScanCallback); // TODO, when to stop ?
-        }
-
         // Static device picking
         //byte[] address = new byte[] { (byte)0x00, (byte)0x17, (byte)0xEA, (byte)0x93, (byte)0x9F, (byte)0x75}; // V7
         //byte[] address = new byte[] { (byte)0x00, (byte)0x17, (byte)0xEA, (byte)0x93, (byte)0xA3, (byte)0x8B};
@@ -487,7 +481,16 @@ public class BLEHandler {
         if( bluetoothLeScanner == null )
             bluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
 
-        bluetoothLeScanner.startScan( Collections.singletonList(scanFilter), scanSettings, new MyScanCallback()  );
+        if( bluetoothLeScanner != null ) {
+
+            bluetoothLeScanner.startScan(Collections.singletonList(scanFilter), scanSettings, new MyScanCallback());
+
+        }
+        else {
+
+                mBluetoothAdapter.startLeScan(new UUID[]{UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb")}, mLeScanCallback); // TODO, when to stop ?
+
+        }
 
         Log.i(TAG, "startScan()");