I want to read all sim contacts and phone contacts separately in Android. I searched for this and found lots of people having problem with this and I couldn't find any solution yet. I fond some answer here, but it doesn't work for me. When I test this it give me google contacts:
RawContacts.ACCOUNT_TYPE + " = 'com.google' "
But when I test this it does not give me sim contacts:
RawContacts.ACCOUNT_TYPE + " = 'com.android.contacts.sim' "
Then I found RawContacts are contacts that created by sync adapter in here. That may be the problem. So can anyone tell me the way of getting
Thanks.
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();
}
I found many phones use "com.android.contacts.sim"
in RawContacts.ACCOUNT_TYPE
for sim contacts. But I also found that HTC use "com.anddroid.contacts.sim" (misspelled for android). That is weird.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With