即使已安装插件,也无法使用serialBluetooth函数

时间:2019-06-26 15:53:07

标签: cordova-plugins android-bluetooth

即使我通过在项目文件夹中运行cordova“ plugin add cordova-plugin-bluetooth-serial”命令安装了插件,也无法使用bluetoothSerial函数。我没有收到任何错误,并且该插件存在于plugins文件夹中。

我尝试将插件标签添加到config.xml中,

我尝试将蓝牙权限添加到AndroidManifest.xml

但没有帮助。

我的cordova版本是9.0.0(cordova-lib@9.0.1)


    var app = {

      initialize: function()

    {

    this.bindEvents();

    },

      bindEvents: function () 

    {

    document.addEventListener('deviceready',this.onDeviceReady(), 
    false)},
      onDeviceReady: function () {

        canvas.width = window.innerWidth;

        canvas.height = window.innerHeight;

    window.addEventListener('touchstart', function(event){

    console.log(event.touches);

          touchX = event.touches[0].pageX;

          touchY = event.touches[0].pageY;

          console.log(touchX, touchY);

          if (touchX <= button1.x + button1.width && touchX >= button1.x) 
    {
            if (touchY <= button1.y + button1.height && touchY >= 
    button1.y) {
                check = 1;  // Everything is fine until here. 
                bluetoothSerial.isEnabled(success(), fail()); // the code 
    here and below here is never executed. 
                c.font = "80px Arial";
                c.fillText("here",50,50);
        }
      }

当我使用chrome:// inspect /#devices调试时,我收到:

 serialBluetooth is not defined error.

为什么会这样?

1 个答案:

答案 0 :(得分:0)

原来,有必要包含脚本标签cordova.js。