从 Android Froyo 2.2 检索联系人
我使用以下代码段来获取联系人姓名和号码,它在模拟器上运行良好,但是当我在 Froyo 2.2.1 中安装该应用程序时,它只返回我的姓名,而不是返回它返回的号码, 'null',有人能帮我解决这个问题吗? 将非常感谢任何解决方案。谢谢
ContentResolver r = getContentResolver();
Cursor cursor = r.query(People.CONTENT_URI, null, null, null, null);
// Let activity manage the cursor
// startManagingCursor(cursor);
// Log.d(TAG, "cursor.getCount()=" + cursor.getCount());
// Get value from content provider
int nameIndex = cursor.getColumnIndex(People.NAME);
int numberIndex = cursor.getColumnIndex(People.NUMBER);//OrThrow(People.NUMBER);
cursor.moveToFirst();
StringBuilder s = new StringBuilder();
do {
String name = cursor.getString(nameIndex);
String number = cursor.getString(numberIndex);
s.append(name+ ": " + number + "\n");
} while (cursor.moveToNext());
im using the following code segment to fetch contact names and numbers, it works fine on the emulator, but when i install the app in my Froyo 2.2.1, it just returns me the name, and instead of returning me the number it returns, 'null', can anyone help me solve this issue ?
will greatly appreciate any solution. Thanks
ContentResolver r = getContentResolver();
Cursor cursor = r.query(People.CONTENT_URI, null, null, null, null);
// Let activity manage the cursor
// startManagingCursor(cursor);
// Log.d(TAG, "cursor.getCount()=" + cursor.getCount());
// Get value from content provider
int nameIndex = cursor.getColumnIndex(People.NAME);
int numberIndex = cursor.getColumnIndex(People.NUMBER);//OrThrow(People.NUMBER);
cursor.moveToFirst();
StringBuilder s = new StringBuilder();
do {
String name = cursor.getString(nameIndex);
String number = cursor.getString(numberIndex);
s.append(name+ ": " + number + "\n");
} while (cursor.moveToNext());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
People API 已弃用,请尝试使用已在 android 2.0+ 中引入的 ContactsContract API。
您可以查看 这篇关于使用contactscontract或API文档的博文
The People API is deprecated try using the ContactsContract API which was already introduced for android 2.0+.
You can look at this blog post about using the contactscontract or the api documentation