phonegap resolveLocalFileSystemURL不适用于android上的内容uri

Mic*_*per 5 android uri image cordova webintents

我想在Android版本5.1.1上使用Nexus 4手机从Android图片库接收分享图片.我正在使用phonegap 4.2和一个phonegap WebIntent插件github链接和phonegap文件插件文档链接.

文本和链接工作正常,但当我尝试从Android库共享图像时,我得到一个这样的URI:

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

而不是像file:/// ....

我尝试使用window.resolveLocalFileSystemURL函数来解析这个使用fileEntry对象返回成功的url.但是,当我尝试使用它来读取文件时,我收到代码1000的错误(参见下面的代码和输出).

有趣的是,如果通过img标签显示此URL,我可以看到图像正常.

<img src="" id="test_intent_image">
$('#test_intent_image').attr("src",uri);
Run Code Online (Sandbox Code Playgroud)

这表明问题可能是window.resolveLocalFileSystemURL函数无法处理内容:// ...正确输入uris?

=====参考信息======

这是我正在使用的代码(注意:我尝试使用其他文件函数,如copyTo()到app文件夹,但它给出了相同的错误):

    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");
    }
);
Run Code Online (Sandbox Code Playgroud)

}

当我尝试从图库中共享图像时,这是代码的控制台输出:

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
Run Code Online (Sandbox Code Playgroud)

这是AndroidManifest.xml文件中的intent过滤器.注意:共享工作正常,只是无法解析URL,所以这可能不是问题.

<intent-filter>
<action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>
Run Code Online (Sandbox Code Playgroud)

Mat*_*Way 3

我一直遇到完全相同的问题,没有使用标准文件插件的直接解决方案。

我尝试了这个插件,但是https://github.com/hiddentao/cordova-plugin-filepath仅适用于 android 内容 uri。

您改用此函数,它似乎可以工作。

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