【问题标题】:proximity sensor cordova doesnt´t works接近传感器科尔多瓦不起作用
【发布时间】:2015-07-06 23:41:45
【问题描述】:

我在 Intel XDK 中使用这个插件

http://phonegap-plugins.com/plugins/awoken-well/cordova-plugin-proximity 对于这项工作,但是当我使用它提供的示例 1 时,当我在我的设备(Android)上运行它时,它不起作用。代码如下:

  <!DOCTYPE html>
<html>
<head>
    <title>Prueba del sensor de proximidad</title>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=no">
    <style>
        @-ms-viewport { width: 100vw ; min-zoom: 100% ; zoom: 100% ; }          @viewport { width: 100vw ; min-zoom: 100% zoom: 100% ; }
        @-ms-viewport { user-zoom: fixed ; min-zoom: 100% ; }                   @viewport { user-zoom: fixed ; min-zoom: 100% ; }
    </style>
    
    <link rel="stylesheet" href="css/app.css">
</head>

<body>
    <h1 class="align-center">Sensor de proximidad</h1>
    <p class="align-center">
        Este tipo de sensor se utiliza para evitar los eventos táctiles cuando el dispositivo está cerca de la cara
    </p>


    <script src="cordova.js"></script>          <!-- "Phantom" cordova.js required for projects that use plugins -->

    <script src="js/app.js"></script>           <!-- for your event code, see README and file comments for details -->
    <script src="js/init-app.js"></script>      <!-- for your init code, see README and file comments for details -->
    <script src="xdk/init-dev.js"></script>     <!-- normalizes device and document ready events, see file for details -->

    <script type="text/javascript">
        function onSuccess(state) {
            alert('Proximity state: ' + (state ? 'near' : 'far'));
        };

        navigator.proximity.enableSensor();

        setInterval(function(){
            navigator.proximity.getProximityState(onSuccess);
        }, 3000);
        /*function hola(){
            alert("hola");
        }
        
        setInterval(function(){
            hola();
        }, 1000);*/
        
    </script>
   
</body>
</html>

谁能告诉我怎么了??

谢谢

【问题讨论】:

    标签: cordova phonegap-plugins cordova-plugins intel-xdk


    【解决方案1】:

    查看 init-app.js 文件中的一些代码,其中显示了初始化应用程序的干净方式,您需要等待设备就绪事件才能访问任何插件代码。换句话说,底层的 Cordova 框架必须初始化。此初始化与加载您的应用程序并行进行,而不是按顺序进行,并且通常比加载 DOM 需要更长的时间。

    本质上,有一堆 Cordova 本地代码需要启动,在一切准备就绪之前,您对这些依赖本地代码的插件的调用将会失败。

    【讨论】:

      猜你喜欢
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      • 2017-09-20
      • 2016-08-18
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      相关资源
      最近更新 更多