Retrieve sim card contacts in android programmatically -


in android app want retrieve sim , phone contacts. if execute code separately works fine if combine phone contacts. how both contacts ??? code sim contacts :

private void simcontacts()  {    try      {        string strphonename = null;           string strphoneno = null;        uri simuri = uri.parse("content://icc/adn");       cursor cursorsim = this.getcontentresolver().query(simuri,null,null,null,null);        while (cursorsim.movetonext())       {                strphonename =cursorsim.getstring(cursorsim.getcolumnindex("name"));          strphoneno = cursorsim.getstring(cursorsim.getcolumnindex("number"));          strphoneno.replaceall("\\d","");          strphoneno.replaceall("&", "");          strphonename=strphonename.replace("|","");            log.i("contact: ", "name: "+strphonename+" phone: "+strphoneno);      }          }  catch(exception e)  {      e.printstacktrace();  }  }

try use , number list aa arraylist

public void getnumber(contentresolver cr) {      public static arraylist<string> aa = new arraylist<string>();     cursor phones = cr.query(             contactscontract.commondatakinds.phone.content_uri, null, null,             null, null);      // system.out.println("phone" + phones.getcount());      while (phones.movetonext()) {         string name = phones                 .getstring(phones                         .getcolumnindex(contactscontract.commondatakinds.phone.display_name));         phonenumber = phones                 .getstring(phones                         .getcolumnindex(contactscontract.commondatakinds.phone.number));         // system.out.println(".................." + phonenumber);         aa.add(name);         aa.add(phonenumber);     }     phones.close();// close cursor        // display contact numbers in list } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -