Ankur
Ankur

Reputation: 233

Why is the Phonegap sample app for accelerometer not able to show phone accelerometer data on Nokia 5800?

I have this code from PhoneGap documentation at http://docs.phonegap.com/en/2.9.0/cordova_accelerometer_accelerometer.md.html#Accelerometer

<!DOCTYPE html>
<html>
  <head>
    <title>Acceleration Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
    <script type="text/javascript" charset="utf-8">

    // The watch id references the current `watchAcceleration`
    var watchID = null;

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        startWatch();
    }

    // Start watching the acceleration
    //
    function startWatch() {

        // Update acceleration every 3 seconds
        var options = { frequency: 3000 };

        watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
    }

    // Stop watching the acceleration
    //
    function stopWatch() {
        if (watchID) {
            navigator.accelerometer.clearWatch(watchID);
            watchID = null;
        }
    }

    // onSuccess: Get a snapshot of the current acceleration
    //
    function onSuccess(acceleration) {
        var element = document.getElementById('accelerometer');
        element.innerHTML = 'Acceleration X: ' + acceleration.x         + '<br />' +
                            'Acceleration Y: ' + acceleration.y         + '<br />' +
                            'Acceleration Z: ' + acceleration.z         + '<br />' +
                            'Timestamp: '      + acceleration.timestamp + '<br />';
    }

    // onError: Failed to get the acceleration
    //
    function onError() {
        alert('onError!');
    }

    </script>
  </head>
  <body>
    <div id="accelerometer">Waiting for accelerometer...</div>
  </body>
</html>

I used this code on build.phonegap.com to make an app and downloaded the .wgz file on Nokia 5800 (Symbian). The app got installed and it loads successfully. But it just show "Waiting for accelerometer...". That is, the content of the <div> tag does not change. Why is that?

Upvotes: 3

Views: 2313

Answers (3)

Louay Alakkad
Louay Alakkad

Reputation: 7408

Change src="cordova-x.x.x.js" to src="cordova.js" and it will work.

Upvotes: 1

vineetv2821993
vineetv2821993

Reputation: 937

Change this statement

<script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>

to

 <script type="text/javascript" charset="utf-8" src="cordova.js"></script>

this is for including a JS file named cordova.js which access the native feature of phone. This is the file you can download from phonegap release site here http://phonegap.com/install/

For the latest release of cordova there is no such need to do. Now version is mentioned in the file itself not in the file name. But for make your acceleration code work this time with the latest release dont forget to add the related plugin for device motion.

Upvotes: 2

Ankur
Ankur

Reputation: 233

I got the answer at Phonegap forum. In the line:

<script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>

src should be set to "cordova.js".

Upvotes: 3

Related Questions