Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String contacts = "";
- Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
- while (cursor.moveToNext()) {
- String contactId = cursor.getString(cursor.getColumnIndex(
- ContactsContract.Contacts._ID));
- String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
- if (Boolean.parseBoolean(hasPhone)) {
- Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +"="+ contactId, null, null);
- phones.moveToNext(); //if you are interested in all contact phones do a while()
- String phoneNumber = phones.getString(phones.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER));
- phones.close();
- contacts += cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)) + ":" + phoneNumber + "|";
- }
- }
- cursor.close();
- Log.i("Contacts Info", contacts);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement