tags:

views:

77

answers:

1

Hi, I am trying to search for a particular contact number in call log and in contact book of the android phone.
But I found that the contact number are stored in different way in contact book and call log. For e.g. I have a contact number 9889880912 to search in the call log and contact book.

To do this, I do the following:

add a contact in the android emulator. When i write the contact number for the contact as 9889880912 , it automaticlly gets changed to 988-988-0912 The dash sign (-) are authomatically inserted in the contact number. I saved the number.

Make a call to this number from the emulator.

Now, using my code, when I am searching for a contact number in contact list by 9889880912,it shows no result when I am trying to search by contact number 988-988-0912 , the contact information from contact book is displayed.

However, when I am trying to search for 988-988-0912 in call log history, it is displayed. but when I am trying to search for 9889880912 in call history , I get no result.

Please help me in solving my problem. Ho can I get the contact search by 9889880912 in contact book.

MY code :

/** Search from contact book **/

Cursor phoneResult = context.getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI , columnNames,queryString, new String[] {String.valueOf(phoneNumber)}, null); if(phoneResult.getCount()>0) Log.d("DEBUG","at least one contact with phonenumber");

/** Search from call log **/

   Cursor callLogResult =   context.getContentResolver().query( callLogURI, 
                columnNames,Calls.NUMBER + "=?", 
                new String[]{String.valueOf(mobileNumber)},
                null); 


           if(callLogResult.getCount()>0)
                  Log.d("DEBUG","At least one call Log found");

Please help me in solving my problem. I am stuck with this since a long time and cant find solution.

Thanks, Nishant

A: 

What API level do u use? Any restrictions on that?

If 5 or higher you can try using PhoneLookup, see for example: http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookup.html

hcpl