I am trying to use the following code to read a phone number. But it ever returns the number as data1
. How do I fix this to get the actual number?
minorCursor = contentResolver.query(Phone.CONTENT_URI, new String[] { Phone.NUMBER, Phone.TYPE },
" DISPLAY_NAME = '" + name + "'", null, null);
while (minorCursor.moveToNext()) {
switch (minorCursor.getInt(minorCursor.getColumnIndex(Phone.TYPE))) {
case Phone.TYPE_MOBILE:
phoneNumber = Phone.NUMBER;
break;
case Phone.TYPE_HOME:
phoneNumber = Phone.NUMBER;
break;
case Phone.TYPE_WORK:
phoneNumber = Phone.NUMBER;
break;
case Phone.TYPE_OTHER:
phoneNumber = Phone.NUMBER;
break;
}
}
I got the code from the third response to How to retrieve Contact name and phone number in Android because I assume he is saying that the methods used by the other replies have been deprecated.
Try this
get your phone number like this.
String phoneNumber = minorCursor.getString(minorCursor.getColumnIndex(Phone.NUMBER));
You need to get phone number from cursor
returned above query
.
What you are trying to do is just getting the constant
value in Phone
class
i.e Phone.NUMBER
is constant field in Phone
class, it will not give you phone number