我想在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);
}; …Run Code Online (Sandbox Code Playgroud)