Modify first phone number and saved it android -
i want retrieve first phone number using code below, add 0 in front of number , saved phone number. new , , code below open contact list, user select phone number , phone number displayed toast. however, want first phone number in contact list 0 in front , saved. know not far solution while trying, faster if help. thanks.
public class mainactivity extends activity {
public static final int pick_contact = 1; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // opens activity. note intent.action_get_content // , intent.settype ((button)findviewbyid(r.id.btn_contacts)).setonclicklistener( new onclicklistener() { @override public void onclick(view v) { // user bod suggests using intent.action_pick instead of .action_get_content avoid chooser intent intent = new intent(intent.action_get_content); // bod con't: content_type instead of content_item_type intent.settype(contactscontract.commondatakinds.phone.content_item_type); startactivityforresult(intent, 1); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.activity_main, menu); return true; } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (data != null) { uri uri = data.getdata(); if (uri != null) { cursor c = null; try { c = getcontentresolver().query(uri, new string[]{ contactscontract.commondatakinds.phone.number, contactscontract.commondatakinds.phone.type }, null, null, null); if (c != null && c.movetofirst()) { string number = c.getstring(0); int type = c.getint(1); showselectednumber(type, number); } } { if (c != null) { c.close(); } } } } } public void showselectednumber(int type, string number) { toast.maketext(this, type + ": " + number, toast.length_long).show(); } }
Comments
Post a Comment