Advertisement
Guest User

Untitled

a guest
Jan 12th, 2012
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. String contacts = "";
  2.        
  3.         Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
  4.         while (cursor.moveToNext()) {
  5.            String contactId = cursor.getString(cursor.getColumnIndex(
  6.            ContactsContract.Contacts._ID));
  7.            String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
  8.            if (Boolean.parseBoolean(hasPhone)) {
  9.                 Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +"="+ contactId, null, null);
  10.                 phones.moveToNext(); //if you are interested in all contact phones do a while()
  11.                 String phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
  12.                 phones.close();
  13.                 contacts += cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)) + ":" + phoneNumber + "|";
  14.             }
  15.         }
  16.         cursor.close();
  17.        
  18.         Log.i("Contacts Info", contacts);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement