Save Modified Phone Number to ContactList at respective index Android -
i retrieved position , phone number contact list. need save number in contactlist modifying orignal number. blocked @ step. please give me hint example type position = 2 , number = 3049393. here complete code.
public class mainactivity extends activity { public static final int pick_contact = 1; textview txt_contacts; @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); txt_contacts =(textview)findviewbyid(r.id.txt_contacts); } }); } @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) { string new_num = 0+number; txt_contacts.settext(new_num); } public void updatecontact() { try { arraylist<contentprovideroperation> ops = new arraylist<contentprovideroperation>(); ops.add(contentprovideroperation.newupdate(data.content_uri) .withselection(data.raw_contact_id + " = ?", new string[] {mrawcontactid}) .withselection(data._id + " = ?", new string[] {mdataid}) .withvalue(data.mimetype, email.content_item_type) .withvalue(data.data1, memail) .withvalue(email.type, email.type_home) .build()); getcontentresolver().applybatch(contactscontract.authority, ops); mresult.settext("updated"); } catch (exception e) { // display warning log.w("updatecontact", e.getmessage()); for(stacktraceelement ste : e.getstacktrace()) { log.w("updatecontact", "\t" + ste.tostring()); } context ctx = getapplicationcontext(); int duration = toast.length_short; toast toast = toast.maketext(ctx, "update failed", duration); toast.show(); } } } update :
public void showselectednumber(int type, string number) {
string new_num = 0+number; system.out.println("display name:"+ number); contentvalues _changed_values=new contentvalues(); _changed_values.put(contactscontract.commondatakinds.phone.number,new_num); getcontentresolver().update(uri,_changed_values,contactscontract.commondatakinds.phone._id+"=?", new string[]{integer.tostring(type)}); // if want change number txt_contacts.settext(new_num); }
contentvalues _changed_values=new contentvalues();
// if want change number _changed_values.put(contactscontract.commondatakinds.phone.number,"mention number");
//where have change _id= mention id of particular contact
getcontentresolver().update(uri,_changed_values,contactscontract.commondatakinds.phone.id+"=?",
new string[]{_id} }
Comments
Post a Comment