2

I am new to Android and have been working on an app that needs to get all of the user's contact's phone numbers. Apparently the code I have does not work with the 2.1 SDK. So far here is the code I am using:

String[] projection = new String[] { Phone.NUMBER };
Cursor c = managedQuery( Phone.CONTENT_URI, projection, null, null, null );
int colIndex = -1;
try {
    colIndex = c.getColumnIndexOrThrow( Phone.NUMBER );
} catch( Exception e ) {
    print( e.getMessage() ); 
}

print( "Column Index = " + colIndex ); 

//count is equal to 3
for( int i = 0; i < count; i++ ){
    try {
        print( c.getString( 2 ) ); //the 2 used to be colIndex
    } catch ( Exception e ) {
        print( e.getMessage() ); 
    }
}

It seems that no matter what I pass into c.getString() it keeps telling me that I passed in -1. But I even hardcoded the 2, and it says the same thing. Any help would be much appreciated.

Brandon Delany
  • 45
  • 1
  • 1
  • 4
  • Here's a [link](http://saigeethamn.blogspot.in/2011/05/contacts-api-20-and-above-android.html) or else try [this one.](http://android2011dev.blogspot.in/2011/08/get-android-phone-call-historylog.html) Think it will help you. – Aswathy P Krishnan Mar 06 '12 at 10:26

0 Answers0