【发布时间】:2013-02-27 16:03:34
【问题描述】:
我正在尝试创建一个将String 作为参数的函数,它将返回Contact_ID 用于具有类似String 提供的电话号码的联系人。
我已经找到了下面的代码
private String getContactName (String number)
{
String contactName = "";
ContentResolver context = getContentResolver();
/// number is the phone number
Uri lookupUri = Uri.withAppendedPath(
PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(number));
String[] mPhoneNumberProjection = { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
Cursor cur = context.query(lookupUri,mPhoneNumberProjection, null, null, null);
try
{
if (cur.moveToFirst())
{
contactName = cur.getString(2);
return contactName;
}
}
finally
{
if (cur != null)
cur.close();
}
return contactName;
}
它返回给定号码的所有联系人姓名。 我如何从这里获取联系人 ID?
谢谢!
【问题讨论】:
-
感谢您的快速回复!你能给我一些示例代码吗?
-
你可以在这里修改一些代码:stackoverflow.com/questions/2174048/…
标签: android