|
@@ -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()");
|
|
|
|