cordova unable to open fileURL returned by camera plugin after application restarted

拜拜、爱过 提交于 2019-12-11 06:07:57

问题


I am using cordova version 7.0.1 and the cordova-plugin-camera version 2.4.1. navigator.camera.getPicture(successFunction, failureFunction,options) In the options, I use

destinationType: Camera.DestinationType.FILE_URI
sourceType: Camera.PictureSourceType.PHOTOLIBRARY

I am getting the image URI correctly. I create a "img" element and set the img.src to the URI returned by the plugin The picture appears correctly. Now, I store this URI in the application's local folder, and close the application. I restart the application, and read the imageURI from storage. Then, I create an "img" element and set the img.src to the URI read form storage.

The URI read from storage is identical to the URI earlier returned by the camera plugin getPicture() call. But, the image file is not read and the picture does not appear on screen. The errors I am seeing are Unable to open content URL:

content://com.android.providers.media.documents/document/image%3A3237 URL blocked by whitelist: content://com.android.providers.media.documents/document/image%3A3184

So, I thought this was a whitelist problem. I added into the config.xml file. But this makes the app crash when it tries to read the image file.

I am trying this on a Karbonn phone running Android Marshmallow.

Please do share the solution if you know what is wrong with the above, what else I need to do here.


回答1:


It seems when accessing an image from a "media-store" like the gallery without using "a certain system-app" like the camera, an ordinary app must hold the permission android.permission.MANAGE_DOCUMENTS in order to have access to that image.

Unfortunately ordinary apps do not have this permission, as this answer says. Therefore a gallery-image must be moved/copied into the app-folder (file:///storage/emulated/0/Android/data/APP_NAMESPACE) by using "a system-app" that holds the android.permission.MANAGE_DOCUMENTS-permission so that an ordinary app can show this image after a it was restarted for instance.



来源:https://stackoverflow.com/questions/46283485/cordova-unable-to-open-fileurl-returned-by-camera-plugin-after-application-resta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!