How to search contacts by name and phone number?
You should use Phone.CONTENT_FILTER_URI
instead of Contacts.CONTENT_FILTER_URI
Docs say:
The filter is applied to display names as well as phone numbers.
Try this:
Uri filterUri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(searchString));
String[] projection = new String[]{ Phone.CONTACT_ID, Phone.DISPLAY_NAME, Phone.NUMBER };
Cursor cur = getContentResolver().query(filterUri, projection, null, null, null);
Search contact by phone number
You should have a look at the recommended ContactsContract.PhoneLookup provider
A table that represents the result of looking up a phone number, for example for caller ID. To perform a lookup you must append the number you want to find to CONTENT_FILTER_URI. This query is highly optimized.
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,...
Search a contact using phone number
You need to apply below code to work in Real Mobile with android version 2.1
//String msgSender="Mobile No";
Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(msgSender));
Cursor c = getContentResolver().query(lookupUri, new String[]{ContactsContract.Data.DISPLAY_NAME},null,null,null);
try {
c.moveToFirst();
String displayName = c.getString(0);
} catch (Exception e) {
// TODO: handle exception
}finally{
c.close();
}
in Android 2.1 we have to use ContactsContract
and also PhoneLookup
should be of ContactsContract
.
Make sure you have given below permission.
<uses-permission android:name="android.permission.READ_CONTACTS"/>
google people api search by phonenumbers
Use the canonicalForm of the phoneNumber without the +
sign.
Example:
Request parameter:
Output:
Related Topics
Android: Using Objectanimator to Translate a View with Fractional Values of the View's Dimension
How to Open the Options Menu Programmatically
Equivalent of Clean & Build in Android Studio
Android Copy/Paste from Clipboard Manager
Android Background Service Is Restarting When Application Is Killed
Android: Simulate Wifi in the Emulator
Play an Audio Clip Onto an Ongoing Call
How to Use Dialog Fragment? (Showdialog Deprecated) Android
Action Buttons Doesn't Show Up on Action Bar
Change Package Name for Android in React Native
Android Circular Determinate Progressbar
How to Automatically Uninstall Android App from Device Before Installing a New Version
How to Set Spinner Default Value to Null
Android: Rotate Image Without Loading It to Memory
How to Get Current Buildtype in Android Gradle Configuration
How to Add a Gesture Detector to a View in Android
How to Disable Home Button in Android
Can't Upload Updated APK to Google Play Due to Different Certificate