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

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

问题描述

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

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.

它以前在旧版本的 Android (3.3) 上按预期运行,在 iOS 上运行良好,但现在无法解析 4.4 (KitKat) 上的图像路径.

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).

返回的图像 url 的返回路径类似于:

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

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

当我使用此路径通过 JavaScript 设置为图像 src 时,无法解析 URL 并因此产生加载错误.用相机拍照没有问题,似乎只有从图库中选择现有图片时才会出现.

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.

我尝试过对 base64 进行编码,也尝试过文档 resolveLocalFileSystemURI(); 中提到的方法,但我对这些没有运气.我也试过删除相机插件并重建应用程序,但没有任何乐趣.

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.

我的猜测是 KitKat 处理图库的方式发生了变化,PhoneGap/Camera 插件尚未更新以适应此情况.

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.

推荐答案

Android 4.4 中图像的 URI 编码出现了问题.

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

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

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

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

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.)

似乎您可以做的另一件事是将目标类型设置为 DATA_URL.

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

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

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