问题
I am trying to get the camera working using phonegap build (I am very new to this). The problem is that nothing seems to be firing.
My code:
$(document).on('click', '.add_photo', function(){
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady(){
navigator.camera.getPicture(onSuccess, onFail, {quality:50});
function onSuccess(imageData){
var image=document.getElementById('myImage');
image.src='data:image/jpeg;base64,'+imageData;
}
function onFail(message){
alert(message);
}
}
});
This has been modified from the Phoegap API pages.
config.xml
includes the following lines:
<feature name="http://api.phonegap.com/1.0/camera" />
<feature name="http://api.phonegap.com/1.0/file" />
回答1:
I had the same problem, setting the quality to 20 fixed the problem for Android.
This only seems to be the issue on Android, for IOS you are safe using the quality value of 50.
var cameraParams = {
quality : 20,
destinationType: Camera.DestinationType.FILE_URI
};
navigator.camera.getPicture(onSuccess, onError, cameraParams);
回答2:
Have you included a link to the cordova.js? If you are using phonegap build you don't need to have the cordova file in your project, just add the following script tag to your header:
<script src="cordova.js"></script>
The phonegap build service adds the file automatically for you.
来源:https://stackoverflow.com/questions/15659556/phonegap-build-with-android-camera-not-firing