简体   繁体   English

ionic navigator.camera.getPicture不会从PHOTOLIBRARY返回图像

[英]ionic navigator.camera.getPicture won't return image from PHOTOLIBRARY

I've added cordova-plugin-camera plugin to my ionic app, in order to use both of its adnavtages - take a picture using camera, and get image from the photo gallery. 我已经在我的离子应用程序中添加了cordova-plugin-camera插件,以便同时使用它的两个附件-使用相机拍照并从照片库中获取图像。

Taking a picture using camera works perfectly on my android galaxy s3 device, but getting image from gallery returns NULL in the success result function. 使用相机拍照在我的android galaxy s3设备上可以完美工作,但是从图库中获取图像会在成功结果函数中返回NULL。

I've tried using both $cordovaCamera.getPicture like described here and navigator.camera.getPicture from this example, both returns null as the result param in success method, after i select image on my device. 我已经尝试过使用此处描述的$ cordovaCamera.getPicture和示例中的navigator.camera.getPicture,在我在设备上选择图像后,两者都返回null作为成功方法中的结果参数。

I've tried playing with all of the params, tried getting any of the 3 options of destinationType (DATA_URL, FILE_URL, NATIVE_URI), tried with saving/unsaving to gallery, edit/unedit, encoding type explicity of jpeg, mediaType PICTURE, etc.. none of them worked with PHOTOLIBRARY or SAVEDPHOTOALBUM, but works fine with CAMERA 我尝试使用所有参数,尝试获取destinationType的3个选项(DATA_URL,FILE_URL,NATIVE_URI)中的任何一个,尝试保存/取消保存到图库,编辑/取消编辑,jpeg的编码类型显式,mediaType PICTURE等..他们都没有使用PHOTOLIBRARY或SAVEDPHOTOALBUM,但是使用CAMERA可以正常工作

This is the code i wrote: 这是我写的代码:

ver 1: 版本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
  });

ver 2: 版本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);
}

can anyone advice what could be the problem? 谁能建议可能是什么问题? (why imageURI/imageData is null) maybe i miss some configuration somewhere? (为什么imageURI / imageData为null)也许我错过了某个地方的配置? i'm out of ideas.. 我没主意..

I've asked the same question in Ionic framework forum and fajohann answered that when he has installed an older version of the plugin it worked fine. 我曾在Ionic框架论坛上问过同样的问题,fajohann回答说,当他安装了旧版本的插件时,它运行良好。 I've tried it myself, installing previous versions one by one until i made it working. 我自己尝试过,一个接一个地安装以前的版本,直到我开始工作为止。 I've found out that the latest version that support android (doesnt return NULL when picking an image) is v1.2.0 我发现支持android的最新版本(选择图像时不返回NULL)是v1.2.0

In order to install it you should run the command: 为了安装它,您应该运行以下命令:

ionic plugin add cordova-plugin-camera@1.2.0 离子插件添加cordova-plugin-camera@1.2.0

Using an old version of the plugin is not a good solution, when something doesn't work you have to open an issue on http://issues.cordova.io giving all the relevant information you can provide, so developers can know about the issue and fix it. 使用旧版本的插件不是一个好的解决方案,当无法解决问题时,您必须在http://issues.cordova.io上打开一个问题,并提供您可以提供的所有相关信息,以便开发人员可以发布并修复它。

Luckily somebody reported the issue https://issues.apache.org/jira/browse/CB-10625 and it was fixed. 幸运的是,有人报告了这个问题https://issues.apache.org/jira/browse/CB-10625 ,该问题已得到解决。

The changes will be available on the version 2.1.1 of the plugin, but it has not been released yet. 更改将在插件的2.1.1版本上可用,但尚未发布。 In the meantime you can install the plugin from the github url 同时,您可以从github网址安装插件

ionic plugin add https://github.com/apache/cordova-plugin-camera

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 navigator.camera.getPicture不会调用成功回调 - 离子框架 - cordova - navigator.camera.getPicture doesn’t call success callback - ionic framework - cordova PhoneGap navigator.camera.getPicture不触发回调 - PhoneGap navigator.camera.getPicture don't trigger Callback 画廊错误中的navigator.camera.getPicture错误“无法创建位图” - navigator.camera.getPicture from the gallery error “Unable to create bitmap” navigator.camera.getPicture无法正常工作 - navigator.camera.getPicture not working properly cordova navigator.camera.getPicture 在 android 中不起作用 - cordova navigator.camera.getPicture not working in android navigator.camera.getPicture在android中不起作用 - navigator.camera.getPicture not working in android 为什么我不能在Android应用中使用Cordova 2.7.0触发navigator.camera.getPicture? - Why can't I trigger navigator.camera.getPicture using Cordova 2.7.0 in my Android app? Cordova navigator.camera.getPicture在Android 4.4 KitKat上以意外格式返回FILE_URI - Cordova navigator.camera.getPicture returns FILE_URI in unexpected format on Android 4.4 KitKat from gallery navigator.camera.getPicture不打开设备的默认相机应用程序 - navigator.camera.getPicture dont opens the device's default camera application 错误:使用navigator.camera.getPicture()时出现“不允许加载本地资源” - Error: “Not allowed to load local resource” when using navigator.camera.getPicture()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM