4

How could I search contacts by number entered from keypad? I think android already implemented the T9 algorithm but how can I use this implementation?

Feras Odeh
  • 9,136
  • 20
  • 77
  • 121
  • apparently there is something like that in 4.3 : http://android.stackexchange.com/questions/45008/how-to-search-contacts-with-t9-dialer-on-nexus-4 – njzk2 Aug 11 '14 at 15:00
  • one way could be to generate all permutations and try to put a `in ()` in the where clause in the request, but I don't know about performance. – njzk2 Aug 11 '14 at 15:01
  • what do you actually want? do you want to show suggestion in list when a search string is given as input? – stinepike Aug 14 '14 at 05:10
  • @StinePike yes I want to show suggestions in list. – Feras Odeh Aug 28 '14 at 09:14

1 Answers1

0

I havent tested this... May be this could help..

    String contactId = "";
String contactName = "";

private void retrieveContactRecord(String phoneNo) {
    try{
        Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNo));
        String[] projection = new String[] { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.DISPLAY_NAME };
        String selection = null;
        String[] selectionArgs = null;
        String sortOrder = ContactsContract.PhoneLookup.DISPLAY_NAME+ " COLLATE LOCALIZED ASC";
        ContentResolver cr = mContext.getContentResolver();
        if(cr != null){
            Cursor resultCur = cr.query(uri, projection, selection, selectionArgs, sortOrder);
            if(resultCur != null){
                while (resultCur.moveToNext()) {
                    contactId = resultCur.getString(resultCur.getColumnIndex(ContactsContract.PhoneLookup._ID));
                    contactName = resultCur.getString(resultCur.getColumnIndexOrThrow(ContactsContract.PhoneLookup.DISPLAY_NAME));
                    Log.e("Info","Contact Id : "+contactId);
                    Log.e("Info","Contact Display Name : "+contactName);
                    break;
                }
                resultCur.close();
            }
        }
    }
    catch(Exception sfg){
        Log.e("Error", "Error in loadContactRecord : "+sfg.toString());
    }
}
Bhaskar
  • 911
  • 6
  • 18