diff --git a/README.md b/README.md index 5dec0e1..40becf0 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Add the dependency to the **Module** gradle file: ```gradle dependencies { ... - compile 'com.github.phearme:bt-scan-selector:1.1.4' + compile 'com.github.phearme:bt-scan-selector:1.1.5' } ``` Enable databinding in the **Module** grade file: diff --git a/btscanselector/build.gradle b/btscanselector/build.gradle index 62c5502..7583688 100644 --- a/btscanselector/build.gradle +++ b/btscanselector/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 26 - versionCode 17 - versionName "1.1.4" + versionCode 18 + versionName "1.1.5" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/btscanselector/src/main/java/com/phearme/btscanselector/BTScanSelectorViewModel.java b/btscanselector/src/main/java/com/phearme/btscanselector/BTScanSelectorViewModel.java index ca0e9cd..2949446 100644 --- a/btscanselector/src/main/java/com/phearme/btscanselector/BTScanSelectorViewModel.java +++ b/btscanselector/src/main/java/com/phearme/btscanselector/BTScanSelectorViewModel.java @@ -68,7 +68,9 @@ public void onReceive(Context context, Intent intent) { filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED); filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); context.registerReceiver(mReceiver, filter); - BluetoothAdapter.getDefaultAdapter().startDiscovery(); + if (BluetoothAdapter.getDefaultAdapter() != null) { + BluetoothAdapter.getDefaultAdapter().startDiscovery(); + } } @Bindable @@ -99,7 +101,9 @@ public void onItemResultClick(BTScanResultItem device) { void terminate(Context context) { try { - BluetoothAdapter.getDefaultAdapter().cancelDiscovery(); + if (BluetoothAdapter.getDefaultAdapter() != null) { + BluetoothAdapter.getDefaultAdapter().cancelDiscovery(); + } if (mReceiver != null) { context.unregisterReceiver(mReceiver); } @@ -118,7 +122,9 @@ public int compare(BTScanResultItem btScanResultItem, BTScanResultItem t1) { void refresh() { if (!isScanning()) { devices = new ArrayList<>(); - BluetoothAdapter.getDefaultAdapter().startDiscovery(); + if (BluetoothAdapter.getDefaultAdapter() != null) { + BluetoothAdapter.getDefaultAdapter().startDiscovery(); + } } }