0
我已經安裝了Rand Dusing的BLE Cordova插件,並按照他的示例初始化藍牙,但我無法克服這一點。這是我index.js
插件不工作
var blePlugin = window.bluetoothle;
function bleInitialize() {
var paramsObj = {
request: true,
statusReceiver: true
};
document.getElementById("BTHWStatus").innerHTML = 'Initialze BLE: Checking BT status...';
blePlugin.initialize(bleInitializeSuccess, bleInitializeError, paramsObj);
document.getElementById("BTHWStatus").innerHTML = 'Initialze BLE: Complete';
return false;
}
function bleInitializeSuccess(obj) {
if (obj.status == "enabled")
document.getElementById("BTHWStatus").innerHTML = 'BT is turned ON';
else
document.getElementById("BTHWStatus").innerHTML = 'BLE:Initialize: Unexpected error';
}
function bleInitializeError(obj) {
document.getElementById("BTHWStatus").innerHTML = "Initialize Error : " + JSON.stringify(obj);
}
這是index.html
<h3>Bluetooth Test App</h3>
<br>
<div>
<a id="BTHWStatus">BT is turned OFF</a>
<br/>
<br/>
<span>Enable/Disable Bluetooth :</span>
<input type="checkbox" id="BTSelect">
<button id="BTApply">Apply</button>
<br/>
</div>
誰能告訴我,如果我在index.js
文件的任何不正確,可能會阻止該插頭在不工作?我已經使用命令cordova plugin
驗證了插件已正確安裝在命令提示符中。
回調函數是否正確編碼或者我錯過了什麼?我可以通過blePlugin.initialize
函數在應用頁面上打印Initialze BLE: Checking BT status...
,但之後沒有任何結果。
感謝並感謝您的幫助。
是的,'deviceready'後面的應用程序代碼正在執行,我可以從'deviceready'中調用設備信息(來自cordova-plugin-device的Cordova,Version,Model等)。我也從deviceready調用'bleInitialize'。 – SB77