gpt4 book ai didi

android - 如何从他的号码中获取联系人的姓名

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:38:13 28 4
gpt4 key购买 nike

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

最佳答案

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

关于android - 如何从他的号码中获取联系人的姓名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22652269/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com