Skip to content

Commit 4bfff44

Browse files
author
Silviu Capota-Mera
authored
document getAdapterInfo
1 parent 833db6d commit 4bfff44

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

readme.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Neither Android nor iOS support Bluetooth on emulators, so you'll need to test o
111111
* [bluetoothle.initialize] (#initialize)
112112
* [bluetoothle.enable] (#enable) (Android)
113113
* [bluetoothle.disable] (#disable) (Android)
114+
* [bluetoothle.getAdapterInfo] (#getAdapterInfo) (Android)
114115
* [bluetoothle.startScan] (#startscan)
115116
* [bluetoothle.stopScan] (#stopscan)
116117
* [bluetoothle.retrieveConnected] (#retrieveconnected)
@@ -291,6 +292,27 @@ bluetoothle.disable(disableSuccess, disableError);
291292
The successCallback isn't actually used. Listen to initialize callbacks for change in Bluetooth state. A successful disable will return an error => enable via initialize error callback.
292293

293294

295+
### getAdapterInfo ###
296+
Retrieve useful information such as the address, name, and various states (initialized, enabled, scanning, discoverable).
297+
This can be very useful when the general state of the adapter has been lost, and we would otherwise need to go through a series of callbacks to get the correct state (first initialized, then enabled, then isScanning, and so forth).
298+
The result of this method allows us to take business logic decisions while avoiding a large part of the callback hell.
299+
300+
Currently the discoverable state does not have any relevance because there is no "setDiscoverable" functionality in place.
301+
That may change in the future.
302+
303+
```javascript
304+
bluetoothle.getAdapterInfo(successCallback);
305+
```
306+
307+
##### Success #####
308+
The successCallback contains the following properties:
309+
* name = the adapters's display name
310+
* address = the adapter's address
311+
* isInitialized = boolean value, true if the adapter was initialized, otherwise false
312+
* isEnabled = boolean value, true if the adapter was enabled, otherwise false
313+
* isScanning = boolean value, true if the adapter is currently scanning, otherwise false
314+
* isDiscoverable = boolean value, true if the adapter is in discoverable mode, otherwise false (currently largely false)
315+
294316

295317
### startScan ###
296318
Scan for Bluetooth LE devices. Since scanning is expensive, stop as soon as possible. The Cordova app should use a timer to limit the scan interval. Also, Android uses an AND operator for filtering, while iOS uses an OR operator. Android API >= 23 requires ACCESS_COARSE_LOCATION permissions to find unpaired devices. Permissions can be requested by using the hasPermission and requestPermission functions. Android API >= 23 also requires location services to be enabled. Use ```isLocationEnabled``` to determine whether location services are enabled. If not enabled, use ```requestLocation``` to prompt the location services settings page.

0 commit comments

Comments
 (0)