Skip to content

Commit

Permalink
handle devices with no default bt device
Browse files Browse the repository at this point in the history
  • Loading branch information
r-cohen committed Apr 2, 2018
1 parent 472c432 commit 33f0922
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions btscanselector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}
}
}

Expand Down

0 comments on commit 33f0922

Please sign in to comment.