【发布时间】:2014-05-04 08:09:40
【问题描述】:
我正在制作一个呼叫阅读器应用程序,我可以在其中找出来电的号码,但现在我希望我的应用程序说出正在拨打电话的联系人的姓名。我无法找到联系人的姓名。任何人都可以帮忙。 谢谢
【问题讨论】:
标签: android
我正在制作一个呼叫阅读器应用程序,我可以在其中找出来电的号码,但现在我希望我的应用程序说出正在拨打电话的联系人的姓名。我无法找到联系人的姓名。任何人都可以帮忙。 谢谢
【问题讨论】:
标签: android
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;
}
更多详情Visit this
【讨论】:
要获取来电号码的名称,请使用
name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NAME));
【讨论】: