PhoneGap的/科尔多瓦3.1.0,无法显示联系人照片科尔、联系人、多瓦、照片

由网友(回忆带着薄荷香)分享简介:我想显示在地址簿中所有的联系人,连同他们的照片。I'm trying to display every contact in the address book, together with their photo.要做到这一点,我已经建立了仿真器接触一个随机的图片。我已成功地列出不闹的联系人。第一次接触含有,如预期...

我想显示在地址簿中所有的联系人,连同他们的照片。

I'm trying to display every contact in the address book, together with their photo.

要做到这一点,我已经建立了仿真器接触一个随机的图片。我已成功地列出不闹的联系人。第一次接触含有,如预期,一个网址的照片:

To do so, I have created a contact in the emulator with a random picture. I have managed to list the contacts without trouble. The first contact contains, as expected, an url to the photo:

{ID:1,rawId:1,显示名:测试哥们1,名:{middleName:哥们, familyName:1,格式化:测试多德1","givenName":"Test"},"nickname":null,"phoneNumbers":null,"emails":null,"addresses":null,"ims":null,"organizations":null,"birthday":null,"note":null,"photos":[{"value":"content://com.android.contacts/contacts/1/photo","type":"url","id":"2","$p$pf":false}],"categories":null,"urls":null}

所以,现在我想显示的图片。这是我在遇到麻烦。在尝试创建我运行到错误的小例子,我添加了URL img标签的第一次接触的PIC:

So, now I'm trying to display the pictures. This is where I'm having trouble. In an attempt to create a minimal example of the error I'm running into, I added an img tag with the URL to the pic of the first contact:

<img id="myimg">
<script type="text/javascript">
    setTimeout(function() {
        console.log('doing my thing');
        var theurl = 'content://com.android.contacts/contacts/1/photo';
        var element = document.getElementById('myimg');
        element.src = theurl;
        console.log('did my thing');
    }, 3000);
</script>

我还没有设法让显示画面。这是日志说:

I have not managed to get the picture displayed. This is what the log says:

I/Web Console( 3304): doing my thing at file:///android_asset/www/index.html:42
E/webcoreglue( 3304): *** Uncaught exception returned from Java call!
W/System.err( 3304): java.io.IOException: read failed: EINVAL (Invalid argument)
W/System.err( 3304):    at libcore.io.IoBridge.read(IoBridge.java:442)
W/System.err( 3304):    at java.io.FileInputStream.read(FileInputStream.java:179)
W/System.err( 3304):    at java.io.InputStream.read(InputStream.java:163)
W/System.err( 3304):    at dalvik.system.NativeStart.run(Native Method)
W/System.err( 3304): Caused by: libcore.io.ErrnoException: read failed: EINVAL (Invalid argument)
W/System.err( 3304):    at libcore.io.Posix.readBytes(Native Method)
W/System.err( 3304):    at libcore.io.Posix.read(Posix.java:123)
W/System.err( 3304):    at libcore.io.BlockGuardOs.read(BlockGuardOs.java:149)
W/System.err( 3304):    at libcore.io.IoBridge.read(IoBridge.java:432)
W/System.err( 3304):    ... 3 more
I/Web Console( 3304): did my thing at file:///android_asset/www/index.html:54

我使用的是科尔多瓦3.1.0和仿真的Andr​​oid设备与平台4.2.2和API级别17。我相信我有设置相关权限(READ_CONTACTS WRITE_CONTACTS ,加入 GET_ACCOUNTS WRITE_EXTERNAL_STORAG​​E READ_EXTERNAL_STORAG​​E 的情况下,他们将帮助)。

I'm using cordova 3.1.0 and an emulated Android device with platform 4.2.2 and API level 17. I believe I have the relevant permissions set (READ_CONTACTS, WRITE_CONTACTS, added GET_ACCOUNTS, WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE in case they would help).

我是什么做错了吗?我怎样才能进一步诊断问题?

What am I doing wrong? How can I further diagnose the problem?

推荐答案

去能够解决该问题后才能回答我的问题。

Going to be replying to my own question after being able to resolve the issue.

显然,你无法直接直接访问照片的URL。但是,你可以把它转移到临时存储并链接到这一点。这样做的方法,在应答被描述为这样的问题:

Apparently you can't directly access the URL of the photo directly. But you can transfer it to temp storage and link to that. The method to do so is described in the answer to this question:

的PhoneGap resolveLocalFileSystemURI

阅读全文

相关推荐

最新文章