'How to get sim contacts, phone contacts, Google Contacts separately in listview
I already get the Contact of sim here is the code
try{
String m_simPhonename = null;
String m_simphoneNo = null;
Uri simUri = Uri.parse("content://icc/adn");
Cursor cursorSim = this.getContentResolver().query(simUri,null,null,null,null);
while (cursorSim.moveToNext())
{
m_simPhonename =cursorSim.getString(cursorSim.getColumnIndex("name"));
m_simphoneNo = cursorSim.getString(cursorSim.getColumnIndex("number"));
m_simphoneNo.replaceAll("\\D","");
m_simphoneNo.replaceAll("&", "");
m_simPhonename=m_simPhonename.replace("|","");
{
HashMap<String, Object> _item = new HashMap<>();
_item.put("name", "" +m_simPhonename);
_item.put("number", "" +m_simphoneNo);
contacts.add(_item);
}
} }catch(Exception e){
e.printStackTrace();
I try to get of only phone contacts here is the code it's not working what's the error and how to get that
try{
String m_simPhonename = null;
String m_simphoneNo = null;
Cursor cursorSim = this.getContentResolver().query(RawContacts.CONTENT_URI, new String[]{RawContacts._ID,RawContacts.ACCOUNT_TYPE}, RawContacts.ACCOUNT_TYPE + " <> 'com.anddroid.contacts.sim' " + " AND " + RawContacts.ACCOUNT_TYPE + " <> 'com.google' " , null, null);
while (cursorSim.moveToNext())
{
m_simPhonename =cursorSim.getString(cursorSim.getColumnIndex("name"));
m_simphoneNo = cursorSim.getString(cursorSim.getColumnIndex("number"));
m_simphoneNo.replaceAll("\\D","");
m_simphoneNo.replaceAll("&", "");
m_simPhonename=m_simPhonename.replace("|","");
{
HashMap<String, Object> _item = new HashMap<>();
_item.put("name", "" +m_simPhonename);
_item.put("number", "" +m_simphoneNo);
contacts.add(_item);
}
} }catch(Exception e){e.printStackTrace();}
Now how I get for google account for every account separately is it necessary to use Google people API for this or I get the Google contact without that
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
