cordova unable to open fileURL returned by camera

2019-07-29 13:04发布

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条回答
贪生不怕死
2楼-- · 2019-07-29 13:34

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.

查看更多
登录 后发表回答