Contact.java

qijingxi
pbhqa7wr4 7 months ago
parent 392338e60c
commit 48951e8adb

@ -24,7 +24,15 @@ import android.telephony.PhoneNumberUtils;
import android.util.Log;
import java.util.HashMap;
/**
*
* @ProjectName: minode
* @Package: net.micode.notes.data
* @ClassName: Contact
* @Description:
* @Author: qijingxi
* @Date: 2024-12-30 15:13
*/
public class Contact {
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
@ -35,25 +43,32 @@ public class Contact {
+ "(SELECT raw_contact_id "
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
/**
* @method getContact
* @description
* @date: 2024-12-30 15:13
* @author: qijingxi
* @return string
*/
public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();
}
// 查找HashMap中是否有phoneNumber的信息
if(sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
}
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
Cursor cursor = context.getContentResolver().query(
// 查找数据库中phoneNumber的信息
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME },
selection,
new String[] { phoneNumber },
null);
// 检查是否查询到联系人找到则将相关信息加入HashMap中未找到则处理异常
if (cursor != null && cursor.moveToFirst()) {
try {
String name = cursor.getString(0);

Loading…
Cancel
Save