如何在Android通讯录中查找人
我正在尝试在 Android 的地址簿中实现人员查找。这就是我实现它的方式:
Cursor cur = this.context.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, null, Data.DISPLAY_NAME + "=?", new String[] { mKey }, null);
if (cur.moveToFirst()) {
Intent n = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
((Activity) this.context).startActivityForResult(n, PICK_REQUEST);
if (PICK_REQUEST != 0) {
if (Activity.RESULT_OK != 0) {
((Activity) this.context).startActivity(n);
}
}
} else {
Toast.makeText(this.context, "The contact does not exist", Toast.LENGTH_LONG).show();
// }
其中 mKey
是要搜索的人的值。当我点击搜索时似乎什么也没有发生。我做错了什么?请指教。
谢谢。
I am trying to implement person lookup in Android's address book. This is how I am implementing it:
Cursor cur = this.context.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, null, Data.DISPLAY_NAME + "=?", new String[] { mKey }, null);
if (cur.moveToFirst()) {
Intent n = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
((Activity) this.context).startActivityForResult(n, PICK_REQUEST);
if (PICK_REQUEST != 0) {
if (Activity.RESULT_OK != 0) {
((Activity) this.context).startActivity(n);
}
}
} else {
Toast.makeText(this.context, "The contact does not exist", Toast.LENGTH_LONG).show();
// }
whereby mKey
is the value of the person to search for. Nothing seems to happen when I click to search. What is it that am doing wrong? Please advise.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用:
只需检查 cur.getCount()>0 即可知道您是否正在获取相关数据。希望您的通讯录中有名为 mKey 的联系人,否则您将始终得到空光标。 :P
Try using :
Just check for cur.getCount()>0 to know whether you are getting related data or not.Hope,you have contact in your contact book with name mKey,else you will always get null cursor. :P
尝试此代码,将 A1 替换为您的显示名称
Try this code, replace A1 with your Display Name