一切都在标题中,我通过Camera.getPicture方法访问相机,我可以选择一张照片或拍摄一张照片但是当我正在访问照片库或照相机拍照时,我的错误回调被解雇了,所以我无法取回图片的URI。它没有崩溃我的应用程序我仍然可以使用它。 我已经尝试使用Android的“Foreground Camera插件”,但每次都会触发错误回调。
我收到错误消息:“07-09 18:33:55.728:D / CordovaLog(10038):错误:相机已取消。”
我正在使用三星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>
答案 0 :(得分:4)
检查您的AndroidManifest.xml
文件,确保您的应用的相机权限存在:
<uses-permission android:name="android.permission.CAMERA" />
如果它不存在,那么它可能适用于你的Galaxy Tab,因为旧版本的Android在默认情况下更适合应用程序可以做什么,但是你的S2有更新版本的Android并且需要显式权限才能允许访问到相机。
编辑:根据此Google Groups discussion,尝试更改该行:
android:launchMode="singleInstance"
到
android:launchMode="singleTask"
config.xml
中的
答案 1 :(得分:0)