2014-12-02 196 views
0

我正在開發一個應用程序,可從手機中檢索所有聯繫人詳細信息(號碼,姓名,電子郵件,照片)。它顯示正確的所有細節,但問題是電子郵件ID顯示相同的手機號碼。所以如何解決這個問題。下面是代碼片段。請幫助我如何從手機獲取所有聯繫人詳細信息

Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; 
      Cursor cursor = getApplicationContext().getContentResolver().query(uri, new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER, 
       ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone._ID, 
       ContactsContract.CommonDataKinds.Email.ADDRESS}, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC"); 
      cursor.moveToFirst(); 
      while (cursor.isAfterLast() == false) 
      { 
       String contactNumber= cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); 
       String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); 
       String emailId = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS)); 
       // int phoneContactID = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID)); 

       Contact contact = new Contact(); 
       contact.setConatctId(count++); 
       //contact.setConatctId(phoneContactID); 
       contact.setEmailId(emailId);    
       contact.setDisplayName(contactName);     
       contact.setMobileNo(contactNumber); 
+1

看到我的答案在這裏:http://stackoverflow.com/questions/26804387/android-fetch-all-contact-list-name-email-phone-takes-more-then-a-minute-for – pskink 2014-12-02 12:21:59

+0

我已經試過這個,但它花費太多時間 – 2014-12-02 12:25:27

+0

太多時間?你一定是在開玩笑,不是嗎?我有60個聯繫人,它花了25毫秒(即0.025秒) – pskink 2014-12-02 12:29:09

回答

相關問題