我已添加cordova-plugin-camera插件到我的 ionic 应用程序,以便使用它的两个adnavtages - 使用相机拍照,并从照片库获取图像。
使用相机拍照在我的 Android Galaxy s3 设备上完美运行,但从图库获取图像在成功结果函数中返回 NULL。
我已经尝试使用 $cordovaCamera.getPicture 就像所描述的 here和 navigator.camera.getPicture 来自 this例如,在我在设备上选择图像后,两者都会返回 null 作为 success 方法中的结果参数。
我尝试过使用所有参数,尝试获取destinationType(DATA_URL、FILE_URL、NATIVE_URI)的3个选项中的任何一个,尝试保存/取消保存到图库、编辑/取消编辑、jpeg、mediaType的显式编码类型图片等. 它们都不适用于 PHOTOLIBRARY 或 SAVEDPHOTOALBUM,但适用于 CAMERA
这是我写的代码:
版本 1:
var options = {
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
correctOrientation: true,
allowEdit: true
};
$cordovaCamera.getPicture(options)
.then(function (imageURI) {
if (!imageURI) {
console.log('getPicture: no image selected');
return;
}
// upload image to server code goes here
});
版本 2:
navigator.camera.getPicture(onSuccess, onFail,
{
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
correctOrientation: true,
allowEdit: true
});
function onSuccess(imageData) {
console.log(imageData);
// upload image to server code goes here
}
function onFail(message) {
alert('Failed because: ' + message);
}
任何人都可以建议可能是什么问题吗? (为什么 imageURI/imageData 为空) 也许我在某个地方错过了一些配置?我没有主意了..
最佳答案
我在 Ionic 框架中问了同样的问题 forum fajohann 回答说,当他安装旧版本的插件时,它工作得很好。我自己尝试过,一一安装以前的版本,直到它工作为止。 我发现支持android的最新版本(选择图像时不返回NULL)是v1.2.0
为了安装它,您应该运行以下命令:
ionic plugin add [email protected]
关于android - ionic navigator.camera.getPicture 不会从 PHOTOLIBRARY 返回图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35243605/