Happy New Year.
I have been developing a Cordova app on Android that uses Bluetooth Low Energy (BLE). To accomplish this, I have been using Don Coleman's cordova-plugin-ble-central. This is a neat plugin with a pretty simple API that lets you do serial communications over BLE. It is compatible with both Android AND iOS. It's installable with NPM, but I recommend you get it directly from his Github. The one on NPM seems to be broken on newer Android devices. The issue is that Google now requires ACCESS_FINE_LOCATION permission if you are using bluetooth, and the one on NPM is older and hasn't been updated to request this permission. But that's not really what this post is about.
My app is essentially a remote control for a light. All I am trying to do is communicate over bluetooth when the app is in the foreground. However, the Don Coleman plugin demands the BACKGROUND_LOCATION permission (presumably this would be required if I was trying to continue to send/receive data notifications while the app is in the background). The problem is that this permission comes with some fairly hefty declaration requirements if you are trying to get your app into the Play Store. For example, you have to make a video demonstrating the feature in your app that makes use of this functionality. As I stated earlier, I have no such feature so it will be impossible for me to get my app to pass review.
The only solution I could see was to fork Don's plugin and remove the BACKGROUND_LOCATION permission. So far it seems to work. If you have a similar problem, perhaps you can benefit from this version of the plugin as well. A couple of things:
- In case it doesn't go without saying, if your app is in the background, you will not be able to do Bluetooth communication using this version of the plugin.
- I have only made changes to the Android side. I don't know if the iOS side still somehow requests BACKGROUND_LOCATION permission. If it does, I will ultimately need to address that as well since my app is going to be available for both platforms.
So here it is: High Tech Harmony's cordova-plugin-ble-central without BACKGROUND_LOCATION
To use it, go to your Cordova build folder of your project and do the following:
(only if you have Don's plugin already)
cordova plugin remove cordova-plugin-ble-central
cordova plugin add https://github.com/HighTechHarmony/cordova-plugin-ble-central
cordova clean android
cordova build android
Comments