I installed the Cordova camera plugin for my App. When I am running the index.html on my Computer it says 'TypeError: navigator.camera is undefined' when I am running the Camera function. This MAY (i dont know) happens because the Plugin just works on the the mobile. Then I build the Cordova App, nothing went wrong... and installed it on my phone. Now thers also nothing happening when I click on th 'Gallery'-Button.
MY CODE
<body>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<input type="button" value="Gallery" onclick="getPhoto()"/>
<img id="myImage" src="#" />
<script>
function getPhoto() {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI});
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed because: ' + message);
}
}
</script>
</body>
These are all steps I did (forgot one?):
- create new cordova project
- add Camera Plugin: cordova plugin add cordova-plugin-camera
add permissions in platform/android/Manifest.xml:
uses-permission android:name="android.permission.CAMERA" / uses-feature android:name="android.hardware.camera" / uses-feature android:name="android.hardware.camera.autofocus" /
write the code which I just posted
- build the app
Did I forgot something or why did it went wrong?