查询联系人-SOMETIMES返回空游标 [英] querying contacts - SOMETIMES returns empty cursor

查看:128
本文介绍了查询联系人-SOMETIMES返回空游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查询联系人的显示名称:

I'm trying to query contact's display name:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQ_CODE_PICK_CONTACT:
        if (resultCode == Activity.RESULT_OK) {
            Uri contactUri = data.getData();

            ContentResolver cr = getActivity().getContentResolver();
            Cursor c = cr.query(contactUri, null, null, null, null);

            if (c != null && c.moveToFirst()) {
                //get the contact name
            }
        }
        break;
    }
}

现在这是问题所在:

对于某些联系人,光标返回空,但我不知道为什么. 我检查了contactUri的值,它看起来像:content://com.android.contacts/data/3032

For some contacts the cursor returns empty, and I don't figure out why. I checked the value of contactUri, it looks like: content://com.android.contacts/data/3032

我尝试过的所有类型的联系人(Facebook,Google,电话等)的Uri外观都相同.

The Uri looks the same for all types of contacts I tried - facebook, google, phone etc.

对于某些联系人,光标返回结果,这很好,我可以提取名称.但是对于其他人,即使ContentUri完全相同,它还是有空的,它起源于Intent.getData().

For some contacts the cursor returns with a result, which is good and I can extract the name. But for others it's somehow empty even though the ContentUri is exactly the same, It was originated from Intent.getData().

以下一些事实可能与这个奇怪的问题有关:

Here are some facts that may have something to do with this weird problem:

  • 所有具有空光标的联系人都是facebook联系人. Uri就像上面一样.

  • All the contacts that has empty cursor are facebook contacts. the Uri looks like above.

并非所有的Facebook联系人都引起此问题:我有HTC One X,如果操作系统找到联系人之间的联系(例如,如果它检测到类似的电话号码,则可以在联系人之间链接"在电话簿上)一个Gmail帐户和一个Facebook帐户,建议我在它们之间链接").只有未链接"的Facebook联系人返回空.

Not all the facebook contacts cause this: I have HTC One X, which on the phonebook I can "Link" between contacts if the OS finds a relation between them (say, if it detects the similar phone number for a gmail account and facebook acount, it suggests me to "link" between them). Only the facebook contacts who were NOT "Linked" returns empty.

现在我突然有了想法.有人遇到过吗?

Right now im out of ideas. Did anyone encountered this before?

谢谢.

推荐答案

我在HTC Incredible S上遇到了同样的问题,这使我认为这可能是HTC手机的问题.无论如何,我最终使用的解决方法是通过使用data意向从捆绑包中检索电话号码.

I had the same problem on an HTC Incredible S, which makes me think that it might be an HTC phones issue. Anyway, the workaround I ended up using is by retrieving the phone number from the bundle you get back with the data intent.

final String phoneNumber = data.getStringExtra("android.intent.extra.PHONE_NUMBER");

这时,您需要执行一些逆向逻辑"以使用

at that point you'll need to do some "reverse logic" to fetch the other data of the contact using PhoneLookup.

这篇关于查询联系人-SOMETIMES返回空游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆