我正在尝试根据 android 1.6 上的电话号码查询联系信息。这是我试过的代码。但是我的光标计数等于 0。
String selection = "PHONE_NUMBERS_EQUAL(" + People.Phones.NUMBER + " , " + phoneNumber + ")";
Cursor cursor = mContext.getContentResolver().query(People.CONTENT_URI,
new String[] {People._ID, People.NAME, People.Phones.NUMBER},
selection, null, null);
你知道为什么它不起作用吗?
谢谢。
最佳答案
您可以指定一个 URI 并使用查询直接通过电话号码获取联系信息..
Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, Uri.encode(phoneNumber));
Cursor cursor = mContext.getContentResolver().query(contactUri, null, null, null, null);
上面代码返回的光标应该包含你正在寻找的联系人,你可以得到你需要的信息......
if(cursor.moveToFirst()){
int personIDIndex = cursor.getColumnIndex(Contacts.Phones.PERSON_ID);
//etc
}
关于android - 如何根据电话号码查询联系方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3249769/