在android中检索带有号码的联系人列表
您好,我想从 android 中的联系人列表中检索姓名和号码,我使用以下代码,它会给我姓名,但不会给我号码,它会为号码提供空值
注意:我正在使用 android 模拟器
public void demo(){
String phoneNumber;
String [] item = new String[]{ People._ID,
People.NAME,
People.NUMBER};
Cursor cur = getContentResolver().query(People.CONTENT_URI ,item , null, null, null);
int phoneNumberIndex = cur.getColumnIndexOrThrow(People.NUMBER);
if (cur != null) {
Log.v("cur not null", "Cursor Not null");
if (cur.moveToNext()) {
Log.v("moveToNext", "Moved to first");
Log.v("moveToNext", "Cursor Moved to first and checking");
phoneNumber = cur.getString(phoneNumberIndex);
System.out.println("****** from_number "+phoneNumber +" *****************");
}
}
}
Hi i want to retrieve name and numbers from contact list in android ,am using following code, it will give me name but not number it gives null value for number
NOTE: am using android emulator
public void demo(){
String phoneNumber;
String [] item = new String[]{ People._ID,
People.NAME,
People.NUMBER};
Cursor cur = getContentResolver().query(People.CONTENT_URI ,item , null, null, null);
int phoneNumberIndex = cur.getColumnIndexOrThrow(People.NUMBER);
if (cur != null) {
Log.v("cur not null", "Cursor Not null");
if (cur.moveToNext()) {
Log.v("moveToNext", "Moved to first");
Log.v("moveToNext", "Cursor Moved to first and checking");
phoneNumber = cur.getString(phoneNumberIndex);
System.out.println("****** from_number "+phoneNumber +" *****************");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它给出 null 因为你试图只检索一个数字..这应该有效..
It gives null because u r trying to retrieve only one number.. this should work..