How to read Android contacts and phone contacts separately

I want to read all SIM contacts and phone contacts separately in Android. I searched for it and found many people having problems with it, and I have not yet found a solution. I like it here , but it doesn't work for me. When I test this, give me google contacts:

RawContacts.ACCOUNT_TYPE + " = 'com.google' " 

But when I check this, it does not give me sim contacts:

 RawContacts.ACCOUNT_TYPE + " = 'com.android.contacts.sim' " 

Then I discovered that RawContacts are the contacts created by the sync adapter in here . This can be a problem. So can anyone tell me how to get

  • All simcontacts
  • All telephone contacts

Thanks.

+6
source share
2 answers

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(); } 
+13
source

I found that many phones use "com.android.contacts.sim" in RawContacts.ACCOUNT_TYPE for SIM contacts. But I also found that HTC uses "com.anddroid.contacts.sim" ( with an error for android). This is strange.

+3
source

Source: https://habr.com/ru/post/906289/


All Articles