Skip to content

Commit f11123f

Browse files
committed
Merge pull request #262 from randdusing/discovery
discovery on reconnect
2 parents b91419c + 8b7a9f1 commit f11123f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ bluetoothle.isConnected(isConnectedSuccess, isConnectedError, params);
13791379

13801380

13811381
### isDiscovered ###
1382-
Determine whether the device's characteristics and descriptors have been discovered, or error if not initialized or never connected to device.
1382+
Determine whether the device's characteristics and descriptors have been discovered, or error if not initialized or not connected to device. Note, on Android, you can connect, discover and then disconnect. isDiscovered will return an error due to the device not being connected. But if you call reconnect and call isDiscovered again, it will return isDiscovered => true since the device stays discovered until calling close().
13831383

13841384
```javascript
13851385
bluetoothle.isDiscovered(isDiscoveredSuccess, isDiscoveredError, params);

src/android/BluetoothLePlugin.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ private void reconnectAction(JSONArray args, CallbackContext callbackContext) {
12861286
}
12871287

12881288
connection.put(keyState, BluetoothProfile.STATE_CONNECTING);
1289-
connection.put(keyDiscoveredState, STATE_UNDISCOVERED);
1289+
//connection.put(keyDiscoveredState, STATE_UNDISCOVERED); //Devices stays discovered even if disconnected (but not closed)
12901290
connection.put(operationConnect, callbackContext);
12911291
}
12921292

@@ -3505,11 +3505,17 @@ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState
35053505
returnObj.remove(keyError);
35063506
returnObj.remove(keyMessage);
35073507

3508+
//Save the old discovered state
3509+
Object discoveredState = connection.get(keyDiscoveredState);
3510+
35083511
//Clear out all the callbacks
35093512
connection = new HashMap<Object, Object>();
35103513
connection.put(keyPeripheral, gatt);
35113514
connection.put(keyState, BluetoothProfile.STATE_DISCONNECTED);
35123515

3516+
//Save state in new connection
3517+
connection.put(keyDiscoveredState, discoveredState);
3518+
35133519
connections.put(device.getAddress(), connection);
35143520

35153521
if (callbackContext == null) {

0 commit comments

Comments
 (0)