This is a migrated thread and some comments may be shown as answers.

Cordova plugins don't work

1 Answer 98 Views
Apache Cordova
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 02 Nov 2014, 09:23 AM
Hi,

I'm trying to get a sample app running using the cordova compass, but each time the error callback is called with error code 3.

Here is the code:

<!DOCTYPE html>
<html>
  <head>
    <title>Compass Example</title>
 
    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">
 
    // The watch id references the current `watchHeading`
    var gWatchID = null;
 
    // Wait for device API libraries to load
    document.addEventListener("deviceready", onDeviceReady, false);
 
    // device APIs are available
    function onDeviceReady() {
        startWatch();
    }
 
    // Start watching the compass
    function startWatch() {
        // Update compass every 3 seconds
        var options = { frequency: 3000 };
 
        if (!gWatchID)
            gWatchID = navigator.compass.watchHeading(onSuccess, onError, options);
    }
 
    // Stop watching the compass
    function stopWatch() {
        if (gWatchID) {
            navigator.compass.clearWatch(watchID);
            gWatchID = null;
        }
    }
 
    // onSuccess: Get the current heading
    function onSuccess(heading) {
        var element = document.getElementById('heading');
        element.innerHTML = 'Heading: ' + heading.magneticHeading;
    }
 
    // onError: Failed to get the heading
    function onError(compassError) {
        alert('Compass error: ' + compassError.code);
    }
 
    </script>
  </head>
  <body>
    <div id="heading">Waiting for heading...</div>
    <button onclick="startWatch();">Start Watching</button>
    <button onclick="stopWatch();">Stop Watching</button>
  </body>
</html>

So far I've:
- created a new cordova app: 
cordova create compassDemo com.example.compassDemo "compassDemo"
- added the android platform
cordova platform add android
- added the device-orientation plugin
cordova plugin add org.apache.cordova.device-orientation
- copied the code above as index.html to the www folder (all other files within this folder were deleted previously)
- built the app
cordova build android
- and started the app
cordova run android

The app is built, deployed and started successfully, but only

According to the documentation only two error code are definded:
CompassError.COMPASS_INTERNAL_ERR = 0; 
CompassError.COMPASS_NOT_SUPPORTED = 20;

So I wonder what's the meaning error code 3?
And what am I doing wrong?

I suppose there's something wrong with the configuration, but I have no clue what!?

I've also tried other plugins like accelerator and geo location, but none of them worked.
(fyi I'm using cordova 4.0.0)

Thanks for your help,
Michael

1 Answer, 1 is accepted

Sort by
0
Zdravko
Telerik team
answered on 05 Nov 2014, 05:17 PM
Hi Michael,

I assume you are aiming to reach Cordova's support as you don't have valid Telerik AppBuilder license and use Cordova's CLI with the latest version of the framework 4.0 which AppBuilder does not support yet.
That is why I suggest looking for helpful information in their issue tracking system and some public forums like StackOverflow.

Regards,
Zdravko
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
Tags
Apache Cordova
Asked by
Michael
Top achievements
Rank 1
Answers by
Zdravko
Telerik team
Share this question
or