【问题标题】:plugin cordova BluetoothLE插件科尔多瓦蓝牙LE
【发布时间】:2014-07-08 15:04:05
【问题描述】:

我在使用 apache cordova 的 BluetoothLE 插件时遇到了一些问题。这是我第一次尝试安装,所以我可能会遗漏一些东西。

在我的仓库中: $cordova 插件 ls com.randdusing.bluetoothle 1.0.0 "蓝牙 LE"

所以应该安装插件。 这是我的 js:

$(document).ready(function(){
    //try to enable bluetooth
    bluetoothle.initialize(initializeSuccess, initializeError, true);
    $("#tiles").append($('Bye'));
});

function initializeSuccess(obj) {
    $("#tiles").append($('Hello'));
}

function initializeError(obj) {
    $("#tiles").append($('Hello'));
}

所以,我应该在我的应用程序页面上显示“Hello”,然后是“Bye”,但它不起作用。我没有碰过cordova生成的任何文件,而是www文件夹。 我错过了什么?

【问题讨论】:

    标签: android cordova bluetooth cordova-plugins


    【解决方案1】:

    好的,我已经成功了。 这是完整的代码:

    index.html:

    <html>
        <head>
            <meta charset="utf-8" />
            <meta name="format-detection" content="telephone=no" />
            <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
            <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
            <link rel="stylesheet" type="text/css" href="css/index.css" />
            <meta name="msapplication-tap-highlight" content="no" />
            <title>Hello World</title>
        </head>
        <body>
            <div class="app">
                <h1>Apache Cordova</h1>
                <div id="deviceready" class="blink">
                    <p class="event listening">Connecting to Device</p>
                    <p class="event received">Device is Ready</p>
                </div>
            </div>
            <script type="text/javascript" src="cordova.js"></script>
            <script type="text/javascript" src="js/index.js"></script>
            <script type="text/javascript">
                app.initialize();
            </script>
        </body>
    </html>
    

    index.js:

    var app = {
        // Application Constructor
        initialize: function() {
            this.bindEvents();
        },
        // Bind Event Listeners
        //
        // Bind any events that are required on startup. Common events are:
        // 'load', 'deviceready', 'offline', and 'online'.
        bindEvents: function() {
            document.addEventListener('deviceready', this.onDeviceReady, false);
        },
        // deviceready Event Handler
        //
        // The scope of 'this' is the event. In order to call the 'receivedEvent'
        // function, we must explicitly call 'app.receivedEvent(...);'
        onDeviceReady: function() {
            app.receivedEvent('deviceready');
        },
        // Update DOM on a Received Event
        receivedEvent: function(id) {
            alert("Hello");
            bluetoothle.initialize(initializeSuccess, initializeError, true);
            alert("Bye");
        }
    };
    
    function initializeSuccess(obj) {
        alert("Success");
    }
    
    function initializeError(obj) {
        alert("Failure");
    }
    

    【讨论】:

      猜你喜欢
      • 2017-12-11
      • 1970-01-01
      • 2018-03-20
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      • 2016-01-29
      • 1970-01-01
      • 2016-08-30
      相关资源
      最近更新 更多