I have used this code to display the name and the phone number of my phone even though it is returning the name only, I would appreciate any answer. does it also works if i have google account synced?
CODE: public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (people != null && people.moveToFirst()) {
do {
try {
int nameFieldColumnIndex = people.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
String contact = people.getString(nameFieldColumnIndex);
Log.d("CONTACT: ", contact);
int numberFieldColumnIndex = people.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);
String number = people.getString(numberFieldColumnIndex);
Log.d("NUMBER: ", number);
} catch (Exception e) {
Log.e("ERROR: ", e.toString());
}
} while (people.moveToNext());
}
}
ERROR:
04-16 05:16:27.839 1426-1426/com.chatter.contactsaccess D/CONTACT:﹕ Test
04-16 05:16:27.839 1426-1426/com.chatter.contactsaccess D/NUMBER:﹕ 1
EDITED