I have an Android Dialer App in which I want to open contacts. I took the code from Stack Overflow itself. But there is an argument in the startActivityForResult
function, PICK_CONTACT
. It is showing error.
else if(id == R.id.action_contacts){
Intent i = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(i, PICK_CONTACT);
}
And the on ActivityResult
function is like this
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (PICK_CONTACT) :
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
if (c.moveToFirst()) {
String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
// TODO Fetch other Contact details as you want to use
}
}
break;
}
}
Please help how to correct this error.