Search code examples
cordovaphonegap-pluginscordova-plugins

PhoneGap: Capture plugin with navigator.device undefined


I'm new to PhoneGap and am trying to figure out how to use the capture plugin. I'm using Cordova 3.5.0. I have run the following command successfully:

cordova plugin add org.apache.cordova.media-capture

I have read examples where a cordova.js or a phonegap.js is being included in the HTML page. However, neither file exists in the project hierarchy that Cordova has created so I don't know how to include it. I've also read that this file is automatically injected by Cordova at build time. So as far as including any JavaScript files, I'm only including my own JavaScript file. Inside that JavaScript file I have code that does this for testing purposes:

alert(navigator.device);
navigator.device.capture.captureImage(function(files) {
    alert(files);
}, function(error) {
    alert(error);
});

The first alert shows that navigator.device is undefined. I'm running this app on the android emulator. To run the app, I'm doing:

cordova emulate android

I assume there's something I need to include or setup in order to get this working. Any help is greatly appreciated.


Solution

  • I figured out I needed to add the following to my HTML page:

    <script type="text/javascript" src="cordova.js"></script>
    

    Although the file does not exist in the project hierarchy, it gets generated when you build the app. The file does not get injected into your HTML pages automatically, it still needs to be manually included where desired.