Reputation: 190859
I'm building a simple BLE application using cordona/phonegap.
I use BLE lock as an example. Everything works fine with `cordova serve': cordova can scan and access available BLE devices with Phonegap Android application.
However, with `cordova run android --device,' I could build a standalone Android app, download the app to my Android device; but no BLE devices are shown when I execute the downloaded app on the Android device.
What might make this difference? Do I need to do something more to make the standalone app access the Android BLE features?
Upvotes: 0
Views: 528
Reputation: 2283
You need to install the cordova bluetooth plugin into the Cordova app.
cordova plugin add cordova-plugin-ble-central
If you're using the phonegap cli, try
phonegap plugin add cordova-plugin-ble-central
The app works when running in the PhoneGap Developer App because the bluetooth plugin is pre-installed in that app. When you're running directly in Cordova, you need to install the plugin yourself.
Before you install the plugin, you can see the error using Chrome. To get the stack trace from the application on your Android device: Open Chrome on your computer, enter chrome://inspect, choose your device. You should see a message like this in the console.
After you install the plugin and redeploy the project, scanning should work.
cordova plugin add cordova-plugin-ble-central
cordova run android --device
Upvotes: 1
Reputation: 190859
Don's answer is (almost) perfect to me, but I think I need to add some more things just in case.
The command I actually used was phonegap plugin add cordova-plugin-ble-central
from this site.
After that, I have a plugin directory created with BLE libraries.
I don't think this step is not necessary, but the site says that these two lines should be added in config.xml, but I could build the app without this step.
<gap:plugin name="cordova-plugin-ble-central" source="npm" />
<preference name="phonegap-version" value="cli-6.1.0" />
I could use this command to build and install the app.
cordova platform add android
cordova run android --device
When I tried some BLE plugins, I guess I installed other plugins. As a result I have com.megster.rordova.ble
and cordova-plugin-ble-central
in my plugins directory. I also guess config.xml and package.json might have some wrong information not to include the correct BLE library.
So, when I clean installed the BLE lock program, and installed the BLE plugin and build the app, everything seems fine.
Upvotes: 0