使用PhoneGap相机插件从Android 4.4(KitKat)的图库中选择时无法加载图片 [英] Unable to load image when selected from the gallery on Android 4.4 (KitKat) using PhoneGap Camera Plugin

查看:206
本文介绍了使用PhoneGap相机插件从Android 4.4(KitKat)的图库中选择时无法加载图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试根据使用PhoneGap / Cordova相机插件从设备图片库中选择的图片,在我的应用中设置img标签的来源。



它以前在旧版本的Android(3.3)上工作,在iOS上运行正常,但现在无法解决4.4(KitKat)上的图像路径。



返回的图片网址的返回路径如下:

  content://com.android.providers.media.documents/document / image%3A352 

当我使用此路径通过JavaScript设置为图像src时,因此产生负载误差。使用相机拍摄照片时没有问题,它只是在从图库中选择现有照片时出现。



我尝试过编码到base64,在文档 resolveLocalFileSystemURI(); 中提到的方法,但我没有运气这些。我也试过删除相机插件和重建应用程序,但没有快乐。



我的猜测是,一些已经改变了KitKat处理图库和PhoneGap /相机的方式

解决方案

Android 4.4中使用图片的URI编码打破了一些问题。 / p>

在此处针对Cordova提交了一个错误: https:/ /issues.apache.org/jira/browse/CB-5398



getPicture ,在Android Quicks部分下,它讨论这个问题,并指向一个StackOverflow问题与解决方法(编辑相机插件的java代码,强制它打开图库应用程序,而不是存储访问框架应用程序。)



你可以做的另一件事是设置目的地类型为DATA_URL。


I'm trying to set the source of an img tag in my app based on the image chosen from the device image gallery using the PhoneGap/Cordova Camera Plugin.

It has worked previously as intended on older versions of Android (3.3) and works fine on iOS but now fails to resolve the image path on 4.4 (KitKat).

The returned path for the returned image url looks something like:

content://com.android.providers.media.documents/document/image%3A352

When I use this path to set as the image src via JavaScript, the URL cannot be resolved and therefore produces a load error. There is no issue when taking a picture with the camera, it only seems to occur when choosing an existing picture from the gallery.

I have tried encoding to base64 and also tried the method mentioned in the docs resolveLocalFileSystemURI(); but I have had no luck with these. I've also tried removing the camera plugin and rebuilding the app but no joy.

My guess is that something has changed with the way KitKat handles the gallery and PhoneGap/Camera plugin haven't been updated to accomodate for this yet.

解决方案

Something broke in Android 4.4 with the URI encoding of images.

A bug has been filed against Cordova here: https://issues.apache.org/jira/browse/CB-5398

In the docs for getPicture, under the Android Quicks section, it discusses this problem and points to a StackOverflow question with a workaround (edit the Camera plugin java code to force it to open the Gallery app instead of the Storage Access Framework app.)

It seems another thing you could do is set the destination type to DATA_URL.

这篇关于使用PhoneGap相机插件从Android 4.4(KitKat)的图库中选择时无法加载图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆