java - Retrieve contact name and phone after startActivityForResult() -


i have started new intent activity result code:

    intent contactpickerintent = new intent(intent.action_pick, phone.content_uri);        startactivityforresult(contactpickerintent, 1); 

and want phone , number:

protected void onactivityresult(int requestcode, int resultcode, intent data) {      if (requestcode == 1) {          if(resultcode == result_ok){              uri contacturi = data.getdata();              string[] pn = {phone.number};              string[] pna = {phone.contact_id};//idk              cursor cp = getcontentresolver().query(contacturi, pn, null, null, null);             cp.movetofirst();              cursor cpa = getcontentresolver().query(contacturi, pna, null, null, null);             cpa.movetofirst();              int numc = cp.getcolumnindex(phone.number);             string num = cp.getstring(numc);              int namec = cpa.getcolumnindex(phone.contact_id);//idk             string name = cpa.getstring(namec);//idk              log.i("", name);          }         if (resultcode == result_canceled) {             //do other stuff         }     } }    

the phone number fine fail retrieve contact's given name!

 uri uri = data.getdata();          cursor cursor = getcontentresolver().query(uri, null, null, null, null);          cursor.movetofirst();         name = cursor.getstring(cursor.getcolumnindex(contactscontract.contacts.display_name));          cursor.movetofirst();         number = cursor.getstring(cursor.getcolumnindex(phone.number)); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -