Android 2.1 How to get phone numbers of contacts

I am new to Android and working on an application that should get all the phone numbers of users. Apparently the code I have does not work with the 2.1 SDK. So far, the code I'm using is here:

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 to c.getString (), it keeps telling me that I passed at -1. But I even encoded 2, and it says the same thing. Any help would be greatly appreciated.

+2
source share
2 answers

For your specific question, see the accepted answer to this question:

Read all contact phone numbers in android

+2
source

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

Hth!

+1
source

Source: https://habr.com/ru/post/1446631/


All Articles