Reputation: 3465
I have a Cordova application for iOS/Android. The Javascript for the application is served by a webserver which ofcourse makes updating of the App very easy - no AppStore releases unless it is a change to a Cordova plugin.
Now, the application uses BLE in several different ways.
Each of the above is essentially a "mini" client of the Cordova BLE plugin that I developed - I cannot use cordova-bluetooth-serial since this plugin only allows 1 Javascript client.
iOS
Under iOS the solution is easy since an App can create as many CBCentralManager instances as required and under the hood iOS will "merge" these requests to the hardware, so my Javascript for "BLE Beacons" creates a new "BluetoothScanner" object which in iOS creates a CBCentralManager and it can perform scans and get advertisement packets for beacons (Eddystone only, it will not see iBeacon since iOS diverts these off to CoreLocation - I digress)
Android
Under Android, I was hoping that once I obtained the BluetoothAdapter singleton instance via
_bluetoothAdapter = bluetoothManager.getAdapter();
that calling
_scanner = _bluetoothAdapter.getBluetoothLeScanner();
would also return a new instance, however it does not it returns a Singleton instance meaning I cannot have seperate "mini" clients each performing their own scan (with their own ServiceUUID filter) like iOS supports.
So, my question is - is there a way of dynamically creating a Service for each "mini" client in the hope that these Services will get their own BluetoothLeScanner ?
I would imagine that between Android Apps they each get their own BluetoothLeScanner singleton instance, so hoping that Services will aswell.
Frankly, I am not fully across the Android Process space so don't understand if this is possible or not.
If not, then I am going to have to "virtualise" the BluetoothLeScanner myself, so using the singleton instance I will have to merge scan requests from the "mini" clients into requests that match all "mini" clients requirements and perhaps filter the advertisements on the fly to the "mini" clients.
Any help much appreciated.
Upvotes: 0
Views: 1441
Reputation: 18452
I'm not sure how it will be different or not whether it's a singleton or not, but the BluetoothLeScanner is a singleton, just see the source code at https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/bluetooth/BluetoothAdapter.java.
You can also certainly create multiple scanners at the same time, just like iOS. Just call startScan with different scanCallback objects each time.
Upvotes: 2