How to get contacts related to social networks (google, yahoo, ...) synchronized with the phone, in android

My problem is that when I receive contacts from the phone, it will receive all the contacts (from the phone, SIM card, social accounts, etc.)

I want to know if I can receive contacts from social accounts separately?

+6
source share
1 answer

While contacts for applications are synchronized, you can request RawContacts (with READ_CONTACTS permission in the manifest) and get them filtered by account type. For instance:

 Cursor c = getContentResolver().query( RawContacts.CONTENT_URI, new String[] { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY }, RawContacts.ACCOUNT_TYPE + "= ?", new String[] { <account type here> }, null); ArrayList<String> myContacts = new ArrayList<String>(); int contactNameColumn = c.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY); while (c.moveToNext()) { // You can also read RawContacts.CONTACT_ID to read the // ContactsContract.Contacts table or any of the other related ones. myContacts.add(c.getString(contactNameColumn)); } 

It is a matter of providing the appropriate type of account. For instance:

  • "com.google" for Gmail,
  • "com.whatsapp" for WhatsApp,
  • "com.skype.contacts.sync" for Skype,
  • &. WITH
+1
source

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


All Articles