【问题标题】:How to get the name of the contact from his number如何从他的号码中获取联系人的姓名
【发布时间】:2014-05-04 08:09:40
【问题描述】:

我正在制作一个呼叫阅读器应用程序,我可以在其中找出来电的号码,但现在我希望我的应用程序说出正在拨打电话的联系人的姓名。我无法找到联系人的姓名。任何人都可以帮忙。 谢谢

【问题讨论】:

标签: android


【解决方案1】:
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

【讨论】:

    【解决方案2】:

    要获取来电号码的名称,请使用

    name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NAME));
    

    【讨论】:

    • 我将如何与我得到的数字进行比较
    猜你喜欢
    • 2011-09-13
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    相关资源
    最近更新 更多