android - 如何添加phonegap蓝牙插件

标签 android cordova bluetooth

我使用 CLI 添加了蓝牙插件,并将以下代码添加到 index.html。但这是行不通的。我是 phonegap 的新手。请帮助包括这个插件。我使用了 tanelign-bluetooth 插件。

<script>
        window.bluetooth.pair(
        function() {   
           alert('Pairing Successful');  
        },
        function(err) {
           alert('There was an error Pairing to a device'+ JSON.stringify(err));  
        }, deviceaddress);

最佳答案

您需要先在设备就绪事件中添加:

document.addEventListener("deviceready", yourCallbackFunction, false);

function yourCallbackFunction(){
    window.bluetooth = cordova.require("cordova/plugin/bluetooth");
}

然后在您的页面中添加此 js: https://github.com/tanelih/phonegap-bluetooth-plugin/tree/master/www

像这样:<script src="bluetooth.js"></script>

文档:https://github.com/tanelih/phonegap-bluetooth-plugin

关于android - 如何添加phonegap蓝牙插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33327667/

相关文章:

android - 是否可以在 android 中记录通话双方(麦克风、扬声器)?

android - ListView 自定义适配器 - 何时调用 notifyDataSetChanged?

javascript - 为什么 XMLHttpRequest 只适用于 Twitter json?

java - 添加 OnClickListener 会使应用程序崩溃

java - Android蓝牙实时数据流慢

android - 为什么使用 Binding Interface 会导致 Class Not Found 异常?

android - Cursor.moveToNext() 返回 false 而 Cursor.getCount() 表示超过 1 行

bluetooth - 蓝牙 LE 允许的最大 ATT_MTU 是多少?

Android Phonegap 屏幕旋转锁杀死了我的应用程序

android - 应用程序图标周围有白色圆圈,适用于 phonegap/cordova 上的 android