Reputation: 349
I am making an call reader application in which i am able to find out the number from which call is coming but now i want my application to say the name of the contact who is placing the call.I am unable to findout the name of the contact. Can anyone help. Thanks
Upvotes: 4
Views: 174
Reputation: 9023
public static String getContactName(Context context, String phoneNumber) {
ContentResolver cr = context.getContentResolver();
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
Cursor cursor = cr.query(uri, new String[]{PhoneLookup.DISPLAY_NAME}, null, null, null);
if (cursor == null) {
return null;
}
String contactName = null;
if(cursor.moveToFirst()) {
contactName = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
}
if(cursor != null && !cursor.isClosed()) {
cursor.close();
}
return contactName;
}
For more Details Visit this
Upvotes: 4
Reputation: 206
To get the name of the incoming call number,use
name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NAME));
Upvotes: 1