【发布时间】:2013-10-25 16:30:24
【问题描述】:
我正在为 Android 上的 PhoneGap 3.0.0 测试 Tanelih's Bluetooth Plugin 的功能。 该插件似乎运行良好;我可以使用链接到 JavaScript 函数的 HTML 按钮打开和关闭蓝牙,并获取 onSuccess/onError 回调以显示函数是否工作的消息。
但是,当我尝试使用window.bluetooth.isEnabled(isEnabledSuccess, isEnabledError);查看是否启用了蓝牙时,无论蓝牙是启用还是禁用,回调始终是 isEnabledSuccess。
这是我的一些 index.html:
<head>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
window.bluetooth.isEnabled(isEnabledSuccess, isEnabledError);
}
function isEnabledSuccess(isEnabled)
{
var element = document.getElementById('status');
element.innerHTML = "Enabled";
}
function isEnabledError(isEnabled)
{
var element = document.getElementById('status');
element.innerHTML = "Disabled";
}
</script>
</head>
<body>
<p id="status"></p>
</body>
这是一些bluetooth.js(我没有接触过这个文件):
Bluetooth.prototype.isEnabled = function(onSuccess, onError)
{
exec(onSuccess, onError, "Bluetooth", "isEnabled", []);
}
这里有一些BluetoothPlugin.java(我没有接触过这个文件):
/**
* Is Bluetooth on.
*
* @param args Arguments given.
* @param callbackCtx Where to send results.
*/
private void isEnabled(JSONArray args, CallbackContext callbackCtx)
{
try
{
callbackCtx.sendPluginResult(new PluginResult(PluginResult.Status.OK, _bluetooth.isEnabled()));
}
catch(Exception e)
{
this.error(callbackCtx, e.getMessage(), BluetoothError.ERR_UNKNOWN);
}
}
有人有什么想法吗?
【问题讨论】:
标签: javascript android cordova bluetooth phonegap-plugins