cordova-plugin-intent
cordova-plugin-intent copied to clipboard
Convert content URL
When sharing to my application from a thirdparty app like google drive, I get files paths looking like this: content://com.google.android.apps.docs.storage.legacy/something...
For some reason, using getRealPathFromContentUrl fires the success callback, but the variable passed to it is null. What can I do to open the file shared in this way? I tried using window.resolveLocalFileSystemURL on the content URL but that doesn't work (it returns a file error). I replaced "content://" with "file://" but this doesn't work either, the file cannot be opened as well. What could be the reason for that? Opening files from the device's photo gallery works fine! Tested on a Samsung Galaxy Alpha with Android 5.0.2. The app was created using PGB cli 6.3.0.
It would be reall nice if someone could point me in the right direction!
+1
I actually managed to solve it using resolveLocalFileSystemURL found in the official file plugin. I cannot tell if this works for all types of content URLs but it seems to be working fine on many 3rd party apps. Furthermore, I don't know why this didn't work while writing the post above. But when you only want to read the file (like I needed to do), using resolveLocalFileSystemURL works fine.
Hi @MBuchalik
So you used resolveLocalFileSystemURL to resolve the content:// URL received? Can you share relevant code how you resolved and read/access the file in your code please?
I'm stuck.
Thanks in advance.
@sido420 Hm I have done this more than a year ago so I can't remember every single step that had to be done. I am using the following function to generate a file object out of the content uri:
function my_function_that_should_be_able_to_convert_the_content_uri(url, success, error) {
window.resolveLocalFileSystemURL(
url,
function (dirEntry) {
if(!dirEntry.isFile) {
error();
return;
}
dirEntry.file(
function(file) {
success(file);
},
function() {
error();
}
);
},
function() {
// An error occured.
error();
}
);
}
Then, you can build yourself a file reader and do whatever you like with.