Phonegap resolveLocalFileSystemURL not working for uri content on Android

I want to get a general image image from the Android image gallery from a Nexus 4 phone on Android version 5.1.1. I am using phonegap 4.2 and the Phonegap WebIntent github plugin and the doc link phone saver file plugin.

Text and links work fine, but when I tried to share the image from the Android gallery, I get the URI as follows:

Content: //com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F63131/ACTUAL

Instead of something like a file: /// ....

I tried using the window.resolveLocalFileSystemURL function to resolve this url, which returns the result successfully with the fileEntry object. However, when I try to use it to read a file, I get an error message with code 1000 (see code and output below).

Interestingly, if I display this URL using the img tag, I can see the image in order.

<img src="" id="test_intent_image"> $('#test_intent_image').attr("src",uri); 

This suggests that the problem may be with the window.resolveLocalFileSystemURL function, which cannot handle the content: // ... is the uris type correct?

===== reference information ======

Here is the code I'm using (note: I tried this with other file functions, such as copyTo (), in the application folder, but it gives the same error):

  document.addEventListener("deviceready", shared, false); document.addEventListener("resume", shared, false); function shared () { window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_STREAM, function(data) { // data is the value of EXTRA_TEXT if (! data) { return; } window.resolveLocalFileSystemURL( data, function (entry) { console.log('file entry: ' + JSON.stringify(entry, null,3) ); function win(file) { var reader = new FileReader(); reader.onloadend = function (evt) { console.log("file read success"); console.log(evt.target.result); }; reader.readAsText(file); }; function fail (error) { console.log("file read error: " + error.code); }; entry.file(win, fail); }, function (error) { console.log('file error: ' + error); }); }, function() { // There was no extra supplied. // debug_log("web intent getExtra: no extra"); } ); 

}

Here is the console output of the code when I tried to share the image with the image gallery:

 handle share stream :"content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F63087/ACTUAL" file entry: { "isFile": true, "isDirectory": false, "name": "ACTUAL", "fullPath": "/com.google.android.apps.photos.contentprovider/0/1/content%3A//media/external/images/media/63087/ACTUAL", "filesystem": "<FileSystem: content>", "nativeURL": "content://com.google.android.apps.photos.contentprovider/0/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F63087/ACTUAL" } file read error: 1000 

Here is the intent filter in the AndroidManifest.xml file. Note: sharing works fine, just cannot resolve the url, so this is probably not a problem.

 <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="*/*" /> </intent-filter> 
+5
source share
2 answers

I had the same problem without a direct solution using a standard plugin.

I tried this plugin, however https://github.com/hiddentao/cordova-plugin-filepath , which is only for uri content for Android.

Instead, you use this function and it seems to work.

window.FilePath.resolveNativePath('content://...', successCallback, errorCallback);

+3
source

This was reported on the website of Cordoba.

https://issues.apache.org/jira/browse/CB-7024

+1
source

All Articles