how to save my phonenumber contact details in sim card android? -


how save phonenumber contact details in sim card android?.i want add contact details directly in sim,not in phone.i using below code save contacts in phone.but facing problem in saving in sim.how can acheive this???

i using following code.

public class mainactivity extends activity {      @override     public void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);           // creating button click listener "add contact" button         onclicklistener addclicklistener = new onclicklistener() {              @override             public void onclick(view v) {                 // getting reference name edittext                  edittext etname = (edittext) findviewbyid(r.id.et_name);                  // getting reference mobile edittext                  edittext etmobile = (edittext) findviewbyid(r.id.et_mobile_phone);                  // getting reference homephone edittext                  edittext ethomephone = (edittext) findviewbyid(r.id.et_home_phone);                  // getting reference homeemail edittext                  edittext ethomeemail = (edittext) findviewbyid(r.id.et_home_email);                  // getting reference workemail edittext                  edittext etworkemail = (edittext) findviewbyid(r.id.et_work_email);                        arraylist<contentprovideroperation> ops =                           new arraylist<contentprovideroperation>();                  int rawcontactid = ops.size();               // adding insert operation operations list                  // insert new raw contact in table contactscontract.rawcontacts                 ops.add(contentprovideroperation.newinsert(contactscontract.rawcontacts.content_uri)                         .withvalue(contactscontract.rawcontacts.account_type, null)                         .withvalue(rawcontacts.account_name, null)                         .build());                  // adding insert operation operations list                 // insert display name in table contactscontract.data                 ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri)                         .withvaluebackreference(contactscontract.data.raw_contact_id, rawcontactid)                         .withvalue(contactscontract.data.mimetype, structuredname.content_item_type)                         .withvalue(structuredname.display_name, etname.gettext().tostring())                         .build());                  // adding insert operation operations list                 // insert mobile number in table contactscontract.data                 ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri)                         .withvaluebackreference(contactscontract.data.raw_contact_id, rawcontactid)                         .withvalue(contactscontract.data.mimetype, phone.content_item_type)                         .withvalue(phone.number, etmobile.gettext().tostring())                         .withvalue(phone.type, commondatakinds.phone.type_mobile)                         .build());                  // adding insert operation operations list                 //  insert home phone number in table contactscontract.data                 ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri)                         .withvaluebackreference(contactscontract.data.raw_contact_id, rawcontactid)                         .withvalue(contactscontract.data.mimetype, phone.content_item_type)                         .withvalue(phone.number, ethomephone.gettext().tostring())                         .withvalue(phone.type, phone.type_home)                         .build());                  // adding insert operation operations list                 // insert home email in table contactscontract.data                 ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri)                         .withvaluebackreference(contactscontract.data.raw_contact_id, rawcontactid)                         .withvalue(contactscontract.data.mimetype, email.content_item_type)                         .withvalue(email.address, ethomeemail.gettext().tostring())                         .withvalue(email.type, email.type_home)                         .build());                  // adding insert operation operations list                 // insert work email in table contactscontract.data                 ops.add(contentprovideroperation.newinsert(contactscontract.data.content_uri)                         .withvaluebackreference(contactscontract.data.raw_contact_id, rawcontactid)                         .withvalue(contactscontract.data.mimetype, email.content_item_type)                         .withvalue(email.address, etworkemail.gettext().tostring())                         .withvalue(email.type, email.type_work)                         .build());                            try{                     // executing insert operations single database transaction                      getcontentresolver().applybatch(contactscontract.authority, ops);                     toast.maketext(getbasecontext(), "contact added", toast.length_short).show();                 }catch (remoteexception e) {                                         e.printstacktrace();                 }catch (operationapplicationexception e) {                     e.printstacktrace();                 }               }         };           // creating button click listener "add contact" button         onclicklistener contactsclicklistener = new onclicklistener() {              @override             public void onclick(view v) {                 // creating intent open android's contacts list                 intent contacts = new intent(intent.action_view,contactscontract.contacts.content_uri);                  // starting activity                 startactivity(contacts);                             }         };           // getting reference "add contact" button         button btnadd = (button) findviewbyid(r.id.btn_add);          // getting reference "contacts list" button         button btncontacts = (button) findviewbyid(r.id.btn_contacts);          // setting click listener "add contact" button         btnadd.setonclicklistener(addclicklistener);          // setting click listener "list contacts" button         btncontacts.setonclicklistener(contactsclicklistener);     }      @override     public boolean oncreateoptionsmenu(menu menu) {         getmenuinflater().inflate(r.menu.activity_main, menu);         return true;     } } 

try add permissions manifest:

<uses-permission android:name="android.permission.read_contacts"/> <uses-permission android:name="android.permission.write_contacts"/> 

and try code:

 private void addcontacttosim(string number, string name)   {  uri simuri = uri.parse("content://icc/adn");  contentvalues values = new contentvalues();  values.put("number", number);  values.put("tag", name);  getcontentresolver().insert(simuri, values);  } 

when saving in phone can save lot of fields example first name, surname, email, adress, add more 1 number. , when saving in sim-card have 2 fields name , number.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -