自定义搜索在Android的联系人 [英] Custom Search for contacts in android
本文介绍了自定义搜索在Android的联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Android的联系人自定义搜索。
I want to custom search in contacts in android.
例如,我想联系人与每个联系人号码结束555 让我怎么能做到这一点?
For example, i want contacts that each contact number end with 555 so how can i do that?
推荐答案
获取所有联系人和手动搜索使用code。
Get all contacts and search manually using code.
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
String phone = null;
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(cur .getColumnIndex(ContactsContract.Contacts._ID));
if (Integer .parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)
{
Cursor pCur = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
while (pCur.moveToNext()) {
phone = pCur .getString(pCur .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
if(phone.endsWith( "555")
// store the number and id of the contact
}
pCur.close();
}
/*** Store id and phone in another variable(eg ArrayList,etc) so that it does not get lost in another iteration of while loop***/
}
}
另外Android的联系人格式与空间 - 和()。它可能是更好的检查之前将其删除。使用
Also Android contacts are formatted with spaces,- and (). it may be better to remove them before checking. Using
phone.replace("-", "").replace("(", "").replace(")", "").replace(".", "").replace(" ", "");
另请参见<一href="http://stackoverflow.com/questions/26859338/check-incoming-number-is-stored-in-contacts-list-or-not-android/26859482#26859482">here.
这篇关于自定义搜索在Android的联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文