2

我是 Android 新手,一直在开发一个需要获取所有用户联系人电话号码的应用程序。显然我的代码不适用于 2.1 SDK。到目前为止,这是我正在使用的代码:

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() ); 
    }
}

似乎无论我传入 c.getString() 什么,它都一直告诉我我传入了 -1。但我什至对 2 进行了硬编码,它也说了同样的话。任何帮助将非常感激。

4

0 回答 0