2013-11-01 31 views
0

我在嘗試獲取聯繫人詳細信息,例如姓名,電話號碼,電子郵件和照片。附加到arraylist中的聯繫人。聯繫方式返回兩次

但是對於同時具有電話號碼和電子郵件地址的聯繫人。我可以首先看到兩個相同的聯繫人姓名,其電子郵件地址爲&,然後是其電話號碼,並且不顯示爲單個聯繫人(應該是)。 任何人都可以請幫我解決這個問題嗎? TIA :)

參考:

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

回答