for phone contacts
try { String[] PROJECTION=new String[] {Contacts._ID, Contacts.DISPLAY_NAME, Phone.NUMBER }; Cursor c=managedQuery(Phone.CONTENT_URI, PROJECTION, null, null, null); if (c.moveToFirst()) { String ClsPhonename = null; String ClsphoneNo = null; do { ClsPhonename = c.getString(c.getColumnIndex(Contacts.DISPLAY_NAME)); ClsphoneNo = c.getString(c.getColumnIndex(Phone.NUMBER)); ClsphoneNo.replaceAll("\\D", ""); ClsPhonename=ClsPhonename.replaceAll("&", ""); ClsPhonename.replace("|",""); String ClsPhoneName=ClsPhonename.replace("|",""); } } while(c.moveToNext()); }
for sim contacts
String ClsSimPhonename = null; String ClsSimphoneNo = null;
Uri simUri = Uri.parse("content://icc/adn"); Cursor cursorSim = this.getContentResolver().query(simUri,null,null,null,null); while (cursorSim.moveToNext()) { ClsSimPhonename =cursorSim.getString(cursorSim.getColumnIndex("name")); ClsSimphoneNo = cursorSim.getString(cursorSim.getColumnIndex("number")); ClsSimphoneNo.replaceAll("\\D",""); ClsSimphoneNo.replaceAll("&", ""); ClsSimPhonename=ClsSimPhonename.replace("|",""); System.out.println("SimContacts"+ClsSimPhonename); System.out.println("SimContactsNo"+ClsSimphoneNo); dts.createDatabse("MyCellFamily",getApplicationContext()); } } catch(Exception e) { e.printStackTrace(); }
source share