且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用PhoneGap相机插件从Android 4.4(KitKat)的图库中选择时无法加载图片

更新时间:2022-10-17 15:44:27

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

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



getPicture ,在Android Quicks部分下,它讨论这个问题,并指向一个***问题与解决方法(编辑相机插件的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 *** 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.