我正在尝试获取联系方式,例如姓名、电话号码、电子邮件和照片。附加到数组列表中的联系人。
但是对于同时具有电话号码和电子邮件地址的联系人。首先,我可以看到两次相同的联系人姓名及其电子邮件地址,然后是其电话号码,并且没有显示为单个联系人(应该是)。谁能帮我解决这个问题?蒂亚:)
参考:
public ArrayList<User> getPhoneContact(String paramString, ArrayList<User> paramArrayList)
throws CustomException
{
//Cursor localCursor = null;
Cursor cursor = null;
ArrayList localArrayList = new ArrayList();
User user;
boolean flag;
String s1;
String s2;
String s6;
String s5;
String s3;
String s4;
int i;
int j;
int k;
int l;
int i1;
try
{
cursor = getNamesAndPictures(paramArrayList);
if(cursor != null && cursor.moveToFirst()){
user = null;
i = cursor.getColumnIndex("data1");
j = cursor.getColumnIndex("contact_id");
k = cursor.getColumnIndex("display_name");
l = cursor.getColumnIndex("data1");
i1 = cursor.getColumnIndex("mimetype");
s1 = null;
do{
s2 = cursor.getString(j);
if(s2 == null)
return localArrayList;
//if(s2.equals(s1))
//return localArrayList;
user = new User();
s1 = s2;
s3 = cursor.getString(k);
user.setName(s3);
user.setContactId(s2);
user.setContactType(paramString);
s4 = cursor.getString(i1);
if(s4 != null){
if(s4.equals("vnd.android.cursor.item/phone_v2")){
s6 = cursor.getString(i);
user.setPhone(s6);
}
else if(s4.equals("vnd.android.cursor.item/email_v2")){
s5 = cursor.getString(l);
user.setEmail(s5);
}
}
localArrayList.add(user);
}while(cursor.moveToNext());
}
}
catch (Exception localException)
{
//localException
}
finally
{
//closeCursor(localCursor);
closeCursor(cursor);
closeDatabase();
}
return localArrayList;
}
和:
private Cursor getNamesAndPictures(ArrayList<User> paramArrayList)
{
String str1 = prepareContactIdsString(paramArrayList);
ContentResolver localContentResolver = this.getAppContext().getContentResolver();
String[] arrayOfString = { "data1", "contact_id", "display_name", "_id", "data1", "mimetype" };
String str2 = "display_name != 'null' AND ( (mimetype = 'vnd.android.cursor.item/phone_v2' AND is_primary != -1 ) OR (mimetype = 'vnd.android.cursor.item/email_v2' AND is_primary != -1 ) ) AND contact_id NOT IN ( " + str1 + ")";
return localContentResolver.query(android.provider.ContactsContract.Data.CONTENT_URI, arrayOfString, str2, null, "display_name COLLATE LOCALIZED ASC");
}