Cordova 版本是:6.3.0
Cordova 安卓版本为:5.0.0
相机插件版本:cordova-plugin-camera 2.2.0 “相机”
我的代码适用于装有 Android 5.0 和 Android 6.0 的多台设备,但不适用于 Android 4.4、Android 4,3 等。
在 Android 4.4 和 4.3 中,相机插件会触发相机和库,但它不会进入 .then(function(ImageData){..} 它会进入错误函数。
$scope.gallery = function() {
var options = {
quality : 80,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit : false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
targetWidth: 500,
targetHeight: 500,
saveToPhotoAlbum: true,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
console.log('image');
imaged = imageData;
$scope.statusMessagePhoto = "photo saved ✓";
}, function(error) {
console.log(error.message);
alert(error.message);
});
};
$scope.savephoto = function(){
var options = {
quality : 80,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
targetWidth: 500,
targetHeight: 500,
saveToPhotoAlbum: true,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
imaged = imageData;
$scope.statusMessagePhoto = "photo saved ✓";
} , function(error) {
console.log(error.message);
alert(error.message);
});
};
当我按下保存照片按钮时,相机打开,但在控制台(日志)中我收到错误“未定义”和警报,甚至在保存或选择我想要的照片之前。
有没有人在 Android 4.3 或 4.4 上遇到过同样的错误。我重复代码在 Android 5.0 及更高版本上完美运行。
最佳答案
已解决!
从 config.xml 中删除这一行
<preference name="AndroidLaunchMode" value="singleInstance"/>
关于android - Android 上的 Ionic Cordova 相机插件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38878963/