Reputation: 127
I am working on call Application in android ,I have done most of things,But now i am working on call logs,I have made a call log,And i want to get all details of a contact from contact book,Using its number programatically,So in short how to get following details from contact book using contact number ,
-Name
-Email
-Photo
-Group
Upvotes: 0
Views: 552
Reputation: 3763
If you want to retrive contact details from phone number use following:
String number = "number to find";
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String name = "?";
ContentResolver contentResolver = getContentResolver();
Cursor contactLookup = contentResolver.query(uri, new String[] {BaseColumns._ID,
ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null);
try {
if (contactLookup != null && contactLookup.getCount() > 0) {
contactLookup.moveToNext();
name = contactLookup.getString(contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
String contactId = contactLookup.getString(contactLookup.getColumnIndex(BaseColumns._ID));
String email = contactLookup.getString(contactLookup.getColumnIndex(BaseColumns.EMAIL));
}
} finally {
if (contactLookup != null) {
contactLookup.close();
}
}
Note Add contact read permission to your manifest
<uses-permission android:name="android.permission.READ_CONTACTS" />
Upvotes: 1