0

I am developing an application in which retrieving all contact details(number, name, email, photo) from mobile. its showing correct all details but problem is that email id is showing same as mobile number. so how to solve this problem.code snippet is below. please help me

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);
Santosh Pandey
  • 190
  • 1
  • 1
  • 10

1 Answers1

0

It could be better to use CursorLoader for fetching data from database using providers. And user CursorAdapter to show the content in listview.

Shiva
  • 39
  • 3