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.
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. 😛