I've been trying to get a bluetooth plugin for PhoneGap working but I can't seem to figure out where I'm going wrong. Firstly, my test device is a Galaxy S3 (GT-19305T) and the applications were built using the PhoneGap CLI.
The plugin I am attempting to use can be found here with an example here.
I tried the example which didn't seem to actually do anything.
So then I went basic, and tried using the plugins with examples given by PhoneGap. I could quite easily get all of these working. In my example, I am using the basic device information plugin.
Here is some example code:
Javascript:
<script type=text/javascript charset=utf-8>
// Wait for device API libraries to load
document.addEventListener(deviceready, onDeviceReady, false);
// device APIs are available
function onDeviceReady() {
var element = document.getElementById('deviceProperties');
element.innerHTML = 'Device Model: ' + device.model + '<br />' +
'Device Cordova: ' + device.cordova + '<br />' +
'Device Platform: ' + device.platform + '<br />' +
'Device UUID: ' + device.uuid + '<br />' +
'Device Version: ' + device.version + '<br />';
var btstatus = document.getElementById('status');
btstatus.innerHTML = Getting bluetooth information;
window.bluetooth.isEnabled(isEnabledSuccess, isEnabledError);
}
function checkBluetoothStatus() {
var btstatus = document.getElementById('status');
btstatus.innerHTML = Checking bluetooth information;
window.bluetooth.isEnabled(isEnabledSuccess, isEnabledError);
}
function isEnabledSuccess(isEnabled){
var btstatus = document.getElementById('status');
if(isEnabled){
btstatus.innerHTML = Enabled;
}else{
btstatus.innerHTML = Disabled;
}
}
function isEnabledError(error){
var btstatus = document.getElementById('status');
btstatus.innerHTML = Cannot determine Bluetooth status: + error.message;
}
function enableBluetooth(){
var btstatus = document.getElementById('status');
btstatus.innerHTML = Attempting to turn bluetooth on;
window.bluetooth.enable(bluetoothTestSucces, bluetoothTestFail);
}
</script>
Html:
<body>
<p id=deviceProperties>Loading device properties...</p>
<br />
<button onclick=enableBluetooth();>Enable Bluetooth</button>
<br />
<button onclick=checkBluetoothStatus();>Check Bluetooth Status</button>
<br />
<p id=status>Loading bluetooth information...</p>
</body>
So basically I am trying to either get the plugin to return the current bluetooth connectivity information, or enable the bluetooth upon clicking the enable bluetooth button.
Unfortunately nothing has worked so far and as I stated earlier I am not sure where I am going wrong.
I have tried applying it manually and by using the CLI.