1

Slightly complicated phrasing, so apologies, but here is the situation.

On my phone, I go to the dial screen and a keypad pops up. I type: "728". Near the top of the list are names like Patrick lastNameson and Paul otherLastNameson. Clearly, the 728 is being converted using the standard alphabet on a phone matching the letters (IE 7 is PQRS, 2 is ABC, 8 is TUV)

My question is, how do I go about querying the name to include a converted number and find the respective contact? Essentially, how does this phone screen on my device search for "Paul" or "Pat" when all I give it is 728?

The code I am using for my query is:

private void myMethod(String query){
    if(query != null){
                phoneWhere = ContactsContract.Data.MIMETYPE +
                        " = ? AND " +
                        "(" +
                        ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME +
                        " LIKE ? COLLATE NOCASE " +
                        "OR " +
                        ContactsContract.CommonDataKinds.Phone.NUMBER +
                        " LIKE ?" +
                        ")";
                phoneWhereParams = new String[]{
                        ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, query, query};

    } else {
            phoneWhere = ContactsContract.Data.MIMETYPE + " = ?";
            phoneWhereParams = new String[]{
                    ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE};
    }


        Cursor pCur = cr.query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                MY_PROJECTION_DEFINED_ELSEWHERE,
                phoneWhere,
                phoneWhereParams,
                SORT_BY_DISPLAY_NAME_STRING_DEFINED_ELSEWHERE);
}

This works perfectly fine and I can use it to query the contact list. But, I want to add in this new feature that reverse engineers how the main dial screen of my device works.

Does anyone have any idea how this code would look? Or can anyone direct me to a sample of what I should be looking for?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
PGMacDesign
  • 6,092
  • 8
  • 41
  • 78
  • it'd probably be a simple table mapping `2` -> `abc`, `3` -> `def`, and then building a query `where name like regex '[abc][def]'` or whatever. – Marc B Aug 11 '16 at 18:28
  • 1
    are you sure its not looking at the phone number of the contact? – tyczj Aug 11 '16 at 18:29
  • @tyczj It's the full name as well as first, middle, last name. You can try on an Android device if you want. For example, `76` will give back "**P**aul **o**therLastNameson" – OneCricketeer Aug 11 '16 at 18:32
  • Maybe you are searching on the `_id` to get the name and the other details? – Phantômaxx Aug 11 '16 at 18:35
  • foreach of your contacts store the hash using `PhoneNumberUtils#convertKeypadLettersToDigits` and then simply use it in `where` clause – pskink Aug 11 '16 at 18:36
  • @cricket_007 On my Android, "76" searches for contacts that _contain_ those digits in a phone number.(as tyczj said) or contacts with names or email addresses _starting_ with those digits (it does not search _in_ names or email addresses, and wouldn't find "fred76@example.com" nor "Fred76" as a first-name). – TripeHound Aug 12 '16 at 08:14
  • @TripeHound - I never said it wouldn't do number searching as well. I was simply pointing out it's not just a simple substring search. It can go across spaces, like the first letter of the first name, followed by the last name. At least on the AOSP / Google dialer. – OneCricketeer Aug 12 '16 at 12:12
  • `I wish mods wouldn't remove the word Android from my question as it just confuses readers, but this is with regards to an Android device` I wish users **don't add tags to their post titles**. *Tags* are there for a purpose. – Phantômaxx Aug 12 '16 at 15:53

0 Answers0