napolitano / cordova-plugin-intent

Plugin for apache cordova (Android Only) that allows interaction with the intent.
MIT License
84 stars 88 forks source link

Convert content URL #14

Open MBuchalik opened 8 years ago

MBuchalik commented 8 years ago

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!

alexislg2 commented 7 years ago

+1

MBuchalik commented 7 years ago

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.

sido420 commented 6 years ago

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.

MBuchalik commented 6 years ago

@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.