一切都在标题中,我正在通过 Camera.getPicture 方法访问相机,我可以选择一张照片或拍照,但是当我访问照片库或相机拍照时,我的错误回调被触发,所以我无法取回图片的URI。它不会使我的应用程序崩溃,我仍然可以使用它。我曾尝试为 android 使用“前景摄像头插件”,但每次仍会触发错误回调。
我收到一条错误消息:“07-09 18:33:55.728: D/CordovaLog(10038): error:Camera cancelled。”
我正在使用三星 Galaxy S2 测试我的应用程序,但是,当我使用 Galaxy Tab 10 测试它时,一切正常,但我需要让它在移动设备上运行。
我正在使用 Cordova 2.7.0 和 AngularJS。
编辑:相关错误信息:
07-09 18:47:47.183: D/DroidGap(11126): Paused the application!
07-09 18:47:47.183: D/CordovaWebView(11126): Handle the pause
07-09 18:47:47.183: D/DroidGap(11126): Incoming Result
07-09 18:47:47.183: D/DroidGap(11126): Request code = 18
07-09 18:47:47.183: D/DroidGap(11126): We have a callback to send this result to
07-09 18:47:47.183: D/DroidGap(11126): Resuming the App
07-09 18:47:47.203: D/DroidGap(11126): Paused the application!
07-09 18:47:47.203: D/CordovaWebView(11126): Handle the pause
07-09 18:47:47.213: W/CordovaPlugin(11126): Attempted to send a second callback for ID: Camera169951334
07-09 18:47:47.213: W/CordovaPlugin(11126): Result was: "No result"
07-09 18:33:55.728: D/CordovaLog(10038): error :Camera cancelled
JavaScript:
$scope.chooseImage = function() {
navigator.notification.confirm('Ajoutez une photo', function (buttonIndex) {
$scope.getImage(buttonIndex);
},'PokeMe',["Prendre","Choisir"])
};
$scope.getImage = function(buttonIndex) {
var sourceType = buttonIndex == 1 ? Camera.PictureSourceType.CAMERA : Camera.PictureSourceType.PHOTOLIBRARY;
var options = {
quality: 80,
destinationType : Camera.DestinationType.FILE_URI,
sourceType: sourceType,
encodingType: Camera.EncodingType.JPEG,
cameraDirection: Camera.Direction.BACK,
correctOrientation: true
}
navigator.camera.getPicture(function (imgData) {
window.safeApply($scope, function() {
console.log('success'+imgData);
$scope.profileSrc = imgData;
});
}, function (msg){console.log('error :'+msg)}, options); //This callback is fired
};
}
HTML:
<div ng-click="chooseImage()" style='margin-top: 30px;margin-bottom: 30px;' id="yellow_btn" ><p><img src='img/upload.png' />Ajoutez une photo</p></div>