Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get contacts associated with social media(google,yahoo,...) synced with phone, in android

Tags:

android

My issue is, when I'm fetching contacts from phone, it will get all the contacts (from phone, SIM, social accounts etc)

i want to know, if I can get contacts from social accounts separately?

like image 887
user2192174 Avatar asked Jun 25 '14 11:06

user2192174


People also ask

How do I sync my contacts with social media?

If you need to sync, head to the “Mail Contacts and Sync” for iPhone or “Accounts & Sync” for Android and make sure the “Sync” option is enabled. Once you've done this your phone will import contacts from Facebook and you will be able to see them in your contacts.

How do I view my Google synced contacts on my phone?

On your Android phone or tablet, open the "Settings" app. Tap Google. Settings for Google apps. Google Contacts sync.


1 Answers

As long as the contacts for the applications are synced, you can query the RawContacts (with the READ_CONTACTS permission in your manifest) and get them filtered by account type. For example:

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's just a matter of supplying the appropriate account type. For example:

  • "com.google" for Gmail,
  • "com.whatsapp" for WhatsApp,
  • "com.skype.contacts.sync" for Skype,
  • &c.
like image 184
matiash Avatar answered Oct 07 '22 09:10

matiash