Reputation: 53873
Following this tutorial I'm trying to get the phone number of a person in the contacts list. With this code I can get the email address:
if (cursor.moveToFirst()){
int emailIdx = cursor.getColumnIndex(Email.DATA);
String email = cursor.getString(emailIdx);
Log.wtf("Email address: ", email);
}
Following this reasoning I tried to get the Phone number like this:
if (cursor.moveToFirst()){
int phoneNrIdx = cursor.getColumnIndex(Phone.DATA);
String phoneNr = cursor.getString(phoneNrIdx);
Log.wtf("Phone number:", phoneNr);
}
Unfortunately this also returns the email address. Does anybody know how I can get the phone number of this contact? All tips are welcome!
Upvotes: 0
Views: 888
Reputation: 8480
Both Email.DATA and Phone.DATA equal the same string, namely 'data1'. That is the name of the column holding the data in the cursor, hence both of your code snippets are effectively the same.
I understand you queried Email.CONTENT_URI, hence the cursor has the email address only in column 'data1'.
To get the phone number as well, close the cursor and then query Phone.CONTENT_URI to get a cursor holding the phone number instead.
Upvotes: 1