Android 2.1系统如何获取联系人的电话号码 [英] Android 2.1 How to get Phone Numbers of contacts
本文介绍了Android 2.1系统如何获取联系人的电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的Android和一直在一个应用程序,需要得到所有用户的联系人的电话号码。显然,code我不与2.1 SDK的工作。到目前为止,这里是code我使用的:
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() );
}
}
看来,不管我传入c.getString()它总是告诉我,我通过在-1。不过,我甚至很难$ C $光盘2,和它说同样的事情。任何帮助将是非常美联社preciated。
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.
推荐答案
有关您的具体问题看在这个问题上公认的答案:
For your specific question see the accepted answer on this question:
这篇关于Android 2.1系统如何获取联系人的电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文