PhoneGap Build with Android Camera not firing

两盒软妹~` 提交于 2020-01-05 07:57:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!