如何在Android上查询ContactsContract.CommonDataKinds.Phone? [英] How to query ContactsContract.CommonDataKinds.Phone on Android?

查看:66
本文介绍了如何在Android上查询ContactsContract.CommonDataKinds.Phone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为SMS消息建立对话列表.因此,我正在阅读"content://sms/conversations",并阅读每个对话的前几条消息以查找通信伙伴的电话号码.使用这些数字,我尝试从ContactsContract.CommonDataKinds.Phone中检索contact_id,以从联系人数据库中获取其他人的信息.

I'm trying to build a conversation list for SMS messages. Therefore I'm reading "content://sms/conversations" and read the first few messages of each conversation to find the communication partners' phone numbers. With these numbers I try to retrieve the contact_id from ContactsContract.CommonDataKinds.Phone to fetch the rest of the person's information from the contacts database.

String[] returnVals = new String[] {ContactsContract.CommonDataKinds.Phone.CONTACT_ID};
Cursor pCur = thisContent.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
            returnVals, 
            ContactsContract.CommonDataKinds.Phone.DATA1 + " = \"" + phoneNumber + "\"", 
            null, 
            null);

当我轮流浏览该查询的结果时,我发现虽然存储在联系人数据库中,但仍未找到某些联系人.例如,一个与我的联系人列表之一相关联的号码位于似乎用破折号存储的州.我知道这可能是个问题,但是我从线程中提取的其他数字以它们在文本消息中出现的方式存储,但仍然找不到.

When I rotate through this query's results I see that some contacts weren't found, although they are stored in the contact database. For example, one number that is associated with one of my contact list and is located in the States that seems to be stored with dashes. I understand that this might be a problem, but other numbers I extracted from the threads are stored the way they appear in the text messages and still don't get found.

所以我的问题是:

  1. 这是正确的方法吗?我想念什么吗?有没有更简单的方法来实现这一目标?
  2. 我从ContactsContract.CommonDataKinds.Phone可以得到的信息是对联系人的_ID的引用.我想我不能像适当的长类型_ID那样处理它,但是我该怎么做呢?
  3. 除了SDK的文档之外,是否还有关于Android中SMS处理的教程,涉及诸如此类的任务?

推荐答案

您应该看看推荐的

You should have a look at the recommended ContactsContract.PhoneLookup provider

代表代表查找电话号码(例如呼叫者ID)的结果的表.要执行查找,您必须将要查找的号码附加到CONTENT_FILTER_URI.此查询已高度优化.

A table that represents the result of looking up a phone number, for example for caller ID. To perform a lookup you must append the number you want to find to CONTENT_FILTER_URI. This query is highly optimized.

Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,...

这篇关于如何在Android上查询ContactsContract.CommonDataKinds.Phone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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