1 Reply Latest reply on Dec 9, 2017 9:28 AM by frodo2975

    Native devicemotion event not firing in phonegap

    frodo2975 Level 1

      I'm getting started with phonegap and am trying to build a motion controlled game. I saw that the device-motion plugin is deprecated, so I'm trying to use the native browser devicemotion event, but it doesn't seem to working in phonegap. The event only fires once, and the values are null. When I view the same code in a regular html page, it works. Any ideas what I'm doing wrong here? I'm using the latest version of the phonegap desktop app and a Nexus 5X phone. Here's my javascript from my index.html page:

       

        document.addEventListener('deviceready', function(){

       

            console.log("deviceready")

       

            window.addEventListener("compassneedscalibration",function(event) {

                console.log('compassneedscalibration')

                // ask user to wave device in a figure-eight motion . 

                event.preventDefault();

            }, true);


            window.addEventListener('devicemotion', function(e) {

                var accel = e.accelerationIncludingGravity;

                alert("got event. x: " + accel.x + ', y: ' + accel.y);

            }, true

        });