From c10e395ebdd947067bfe6df6e717d62fd822f457 Mon Sep 17 00:00:00 2001 From: zkp <3138559151@qq.com> Date: Sat, 16 Dec 2023 19:58:39 +0800 Subject: [PATCH] =?UTF-8?q?ccmt:=20Contact=20mcmt=EF=BC=9AContact.getConta?= =?UTF-8?q?ct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/net/micode/notes/data/Contact.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/micode/notes/data/Contact.java b/src/main/java/net/micode/notes/data/Contact.java index e779900..258b247 100644 --- a/src/main/java/net/micode/notes/data/Contact.java +++ b/src/main/java/net/micode/notes/data/Contact.java @@ -25,6 +25,15 @@ import android.util.Log; import java.util.HashMap; +/** + * + * @ProjectName: minode + * @Package: net.micode.notes.data + * @ClassName: Contact + * @Description: 该类实现了电话号码对应联系人查找的功能 + * @Author: 郑鲲鹏 + * @Date: 2023-12-16 17:57 + */ public class Contact { private static HashMap sContactCache; private static final String TAG = "Contact"; @@ -35,18 +44,29 @@ public class Contact { + "(SELECT raw_contact_id " + " FROM phone_lookup" + " WHERE min_match = '+')"; - + /** + * @method getContact + * @description 该方法用于识别电话号码对应的联系人 + * @date: 2023-12-16 19:24 + * @author: 郑鲲鹏 + * @return string + */ public static String getContact(Context context, String phoneNumber) { if(sContactCache == null) { sContactCache = new HashMap(); } + // 查找HashMap中是否有phoneNumber的信息 + // 2023-12-16 19:43 if(sContactCache.containsKey(phoneNumber)) { return sContactCache.get(phoneNumber); } String selection = CALLER_ID_SELECTION.replace("+", PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); + + // 查找数据库中phoneNumber的信息 + // 2023-12-16 19:43 Cursor cursor = context.getContentResolver().query( Data.CONTENT_URI, new String [] { Phone.DISPLAY_NAME }, @@ -54,6 +74,8 @@ public class Contact { new String[] { phoneNumber }, null); + // 检查是否查询到联系人,找到则将相关信息加入HashMap中,未找到则处理异常 + // 2023-12-16 19:41 if (cursor != null && cursor.moveToFirst()) { try { String name = cursor.getString(0);