I have a phone number. Is there a way to check if a phone number exists in the contacts database on the device or not? Depending on this, I need to move on in my application. Please suggest, or if anyone has a sample code snippet, please provide.
Below is the code I wrote:
public boolean contactExists(Activity _activity, String number) { String[] mPhoneNumberProjection = { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME }; Cursor cur = _activity.getContentResolver().query(number, mPhoneNumberProjection, null, null, null); try { if (cur.moveToFirst()) { return true; } } finally { if (cur != null) cur.close(); } return false; }
Thanks in Advance ...
user1306412
source share