randdusing / ng-cordova-bluetoothle

Angular 1.x wrapper for the PhoneGap/Cordova Bluetooth Low Energy Plugin
Other
47 stars 34 forks source link

android.bluetooth.BluetoothAdapter.getBluetoothLeAdvertiser()' on a null object reference #23

Closed MathGrelck closed 8 years ago

MathGrelck commented 8 years ago

Running the example app on android using cordova run android, I get the following error when trying to advertise in peripheral mode:

Start Advertising Error : "Attempt to invoke virtual method
'android.bluetooth.le.BluetoothLeAdvertiser 
android.bluetooth.BluetoothAdapter.getBluetoothLeAdvertiser()' 
on a null object reference"

The devices I tried running on is both a Samsung Galaxy S6 mini, LG Nexus 5X and Huawei Ascend P7. Same error. I have tried re-adding the plugin. initializePeripheral + addService works fine, but when triggering startAdvertising, I get the error. See the console.log file attached. I have a question more: where is the characteristic "1234" (default for addService, i guess?) set within the code? I have another question (note: my knowledge of BLE is still limited, so excuse me if the question seem dumb, obvious or a non-issue); what is the BLE profile that is used? Is it one supported by Apple, or do I have to get a MFi license when releasing the app to the App Store? Thanks! PS: I also attached the project. console.log.zip https://www.dropbox.com/s/67lut57hpe4mfec/test.zip?dl=0

Edit: Bluetooth is of course enabled and at least the Nexus 5X device should support advertising. I just stumbled on your suggested solution to remove

 || !bluetoothAdapter.isMultipleAdvertisementSupported()

But unfortunately this didn't resolve it for me.

randdusing commented 8 years ago

I actually bought a Nexus 5X a few weeks ago and will double check that I can advertise on it.

The service is added in $rootScope.addService function. This is just a 'random' service UUID that I came up with.

BLE doesn't require any licensing like BT Classic!

randdusing commented 8 years ago

Oh, you need to call bluetoothle.initialize() as well! If I don't call that, I receive the same error. If I call it, it works fine.

MathGrelck commented 8 years ago

Perfect! Thank you so much randdusing.