Android 2.1 How to get Phone Numbers of contacts [duplicate]

ぃ、小莉子 提交于 2019-12-02 04:26:53

问题


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.


回答1:


Please check the following link on how to use the Android 2.0 Contacts API.
http://www.higherpass.com/Android/Tutorials/Working-With-Android-Contacts/

HTH !



来源:https://stackoverflow.com/questions/2901187/android-2-1-how-to-get-phone-numbers-of-contacts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!