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);