Skip to content

Commit

Permalink
Merge pull request #26 from TCNCoalition/bugfix/checkAdapterStateOn-c…
Browse files Browse the repository at this point in the history
…rash

Fix IllegalStateException in BluetoothLeUtils.checkAdapterStateOn
  • Loading branch information
ivnsch authored Jul 1, 2020
2 parents a35d833 + 1ad5508 commit 63e99e8
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.tcncoalition.tcnclient.bluetooth

import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothGatt
import android.bluetooth.BluetoothGattCharacteristic
Expand Down Expand Up @@ -179,11 +180,16 @@ class TcnBluetoothManager(
// state on old Android devices.
handler.removeCallbacksAndMessages(null)
handler.postDelayed({
if (isStarted) {
val adapter = BluetoothAdapter.getDefaultAdapter()
if (isStarted && adapter != null && adapter.isEnabled) {
Log.i(TAG, "Restarting scan...")
// If there are outstanding scan results then flush them so we can process them now
// in onBatchScanResults
scanner.flushPendingScanResults(scanCallback)
try {
scanner.flushPendingScanResults(scanCallback)
} catch (t: Throwable) {
Log.e(TAG, "Scanner couldn't flush pending scan results: $t")
}
stopScan()
startScan()
}
Expand Down

0 comments on commit 63e99e8

Please sign in to comment.