Getting Contact ID from Android Contacts database is not working as intended
I have the following code. int phoneContactID = new Random().nextInt(); Cursor contactLookupCursor = context.getContentResolver().query( Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,Uri.encode(contactNumber)), new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup._ID},null,null,null); try { contactLookupCursor.moveToFirst(); while(contactLookupCursor.moveToNext()) { phoneContactID = contactLookupCursor.getInt(contactLookupCursor.getColumnIndexOrThrow(PhoneLookup._ID)); } } finally { contactLookupCursor.close(); } The problem in the above code is that even if I give a existing number in