【问题标题】:Contact image from Phonegap not displayed来自 Phonegap 的联系人图像未显示
【发布时间】:2014-07-28 09:16:09
【问题描述】:

我看到了一些与此相关的帖子,例如 Ref 但对我不起作用。我试过如下

第一种方法:

从联系人图像值直接设置图像源

var myImg = document.getElementById("cimg");
myImg.src = contacts[i].photos[0].value; 

这个不显示img标签中的图像。

第二种方法:

将联系人图像值传递给 fileDownload 选项

window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fs){
                        fs.root.getFile("temp.jpg", {create: true, exclusive: false},
                          function(entry){
                            //alert(entry.toURL());
                            var fileTransfer = new FileTransfer();
                            fileTransfer.download(
                                    contacts[i].photos[0].value, // the filesystem uri you mentioned
                                    entry.fullPath,
                                    function(entry) {
                                        // do what you want with the entry here
                                        console.log("download complete: " + entry.fullPath);
                                        var src = entry.fullPath; 
                                        //$("").append('<img src="'+src+'" >');
                                    },
                                    function(error) {
                                        alert("error source " + error.source);
                                        console.log("error target " + error.target);
                                        console.log("error code " + error.code);
                                        console.log(error);
                                    },
                                    false,
                                    null
                            );
                        }, function(e){
                            console.log("file create error",e);
                        });
                    }, null);

这个显示像07-28 07:37:56.468: E/FileTransfer(20986): {"target":"file:\/\/\/mnt\/sdcard\/Android\/data\/io.cordova.hellocordova\/cache\/temp.jpg","http_status":0,"code":3,"source":"content:\/\/com.android.contacts\/contacts\/2\/photo","exception":"read failed: EINVAL (Invalid argument)"} 07-28 07:37:56.468: E/FileTransfer(20986): java.io.IOException: read failed: EINVAL (Invalid argument) 这样的错误

编辑:

my phonegap contact[i].photo[0].value 返回类似 "content://com.android.contacts/contacts/1/photo"

如何解决这个问题。请帮帮我。

【问题讨论】:

    标签: javascript android jquery cordova


    【解决方案1】:

    请检查您正在测试的 android 版本。因为android 2.0 -> 2.2 结构有很多变化。你可以在android 4.0 + 上试试吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多