7

I fetched all device contacts from phonebook. Now i want to fetch linked accounts(facebook,twitter,instagram,LinkedIn)urls from that particular contact that is fetched from phonebook.What should i do?

Here is the code to fetch the contacts.

public Cursor getContactsCursor(FragmentActivity activity) {
        Cursor cursor = null;
        try {
            String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + "= 0" + " OR " + ContactsContract.Contacts.IN_VISIBLE_GROUP + "= 1";
            String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
            ContentResolver cr = activity.getContentResolver();
            return cr.query(ContactsContract.Contacts.CONTENT_URI, null, selection, null, sortOrder);
        } catch (Exception e) {
            AppLogger.e(Helper.class.getSimpleName(), e.getMessage());
            return cursor;
        }
    }

Now i don't know how to fetch the accounts (like facebook, linkedin etc) linked with the particular contact.

Can someone please guide me.

Update : In below attached image, On clicking the section highlighted in red, opens the linked in user profile in browser. Hence i am willing to fetch the field which is used to open the user profile page.

enter image description here

Thanks in advance.

Grishma Ukani
  • 636
  • 5
  • 16
  • Are you asking about looking up contacts on those services? So, sending the email to Twitter to see what the user name is? – Terence Eden Sep 20 '17 at 11:02
  • No, i am fetching the contacts from phonebook. Now i want accounts linked with those contacts.Ex.(LinkedIn,Facebook,Instagram,Twitter). – Grishma Ukani Sep 21 '17 at 04:54
  • please explain exactly what you mean by `linked accounts urls`, can you post a screenshot of the info you want to query for from the Contacts app? – marmor Sep 24 '17 at 07:56
  • Yes Sure..I want public profile link of social media if there is any profile link connected to that contact (ex. LinkedIn,Facebook,Twitter,Instagram) from Contacts app. Linked contacts means there is only one contact and if his/her phone number is same in this social media and contacts are synced from that then in contacts app user contact will display as linked contact. – Grishma Ukani Sep 25 '17 at 07:58
  • @marmor Hi i have update the question with the screenshot of the info i want to query. – Grishma Ukani Sep 25 '17 at 08:46

1 Answers1

4

You'll need to figure out the exact MIMETYPE of all accounts you're interested in, for example, Google+'s MIMETYPE is: vnd.android.cursor.item/vnd.googleplus.profile

You can dump all MIMETYPEs for a contact and figure out manually which you need:

// make sure you import Data from: ContactsContract.Data
String[] projection = new String[] { Data.MIMETYPE };
String selection = Data.CONTACT_ID + " = '"+ contactId + "'";
Cursor cursor = getContentResolver().query(Data.CONTENT_URI, projection, selection, null, null);
DatabaseUtils.dumpCursor(cursor);
cursor.close();

Once you have a fixed list of the MIMETYPEs you want, you can query the info in them for a specific contact:

// Add more
String[] mimetypes = new String[] { 
    "vnd.android.cursor.item/vnd.googleplus.profile",
    "vnd.android.cursor.item/vnd.com.whatsapp.profile" 
};

// Usually the interesting info is on the first few fields, modify this if needed
String[] projection = new String[] { Data.DATA1, Data.DATA2, Data.DATA3, Data.DATA4 };
String selection = Data.CONTACT_ID + " = '"+ contactId + "' AND " + Data.MIMETYPE + " IN (?,?)";

Cursor cursor = getContentResolver().query(Data.CONTENT_URI, projection, selection, mimetypes, null);
DatabaseUtils.dumpCursor(cursor);
cursor.close();

UPDATE:

In case of linkedin, the mimetype is indeed: vnd.android.cursor.item/vnd.com.linkedin.android.profile. Regarding your comment about not having the profile url, in Data1 you should have some long ID like AC...UQ4 (about 40 characters).

Then your url is: https://www.linkedin.com/profile/view?id=<data1Id> like: https://www.linkedin.com/profile/view?id=AC...UQ4

marmor
  • 27,641
  • 11
  • 107
  • 150
  • I used this code and get all linkedin contacts information but this code can't able to get me url of profile thhat is connected.. For lonked in mime type is: "vnd.android.cursor.item/vnd.com.linkedin.android.profile" Thanks a lot for your answer. I get field that is highlighted in red box but not getting profile url – Grishma Ukani Sep 25 '17 at 14:30
  • can you please inform me about mime type of facebook, instagram and twitter i also have same process for facebook, instagram and twitter..So can you please help me that what are the mime types for this 3..If you know? – Grishma Ukani Sep 26 '17 at 03:55
  • sorry, i don't know, you'll have to dump the contact data for those and see for yourself. BTW it's not guaranteed that you'll be able to create a profile url out of contact data stored in the android contacts, if i'm not mistaken, if facebook is able to sync contacts on a device, it adds protection not allowing apps to access that data, or it doesn't sync ids/urls at all. – marmor Sep 26 '17 at 04:21
  • Yes you are right..Facebook is not allowing user to sync contacts into contacts app.So i think instagram also not allowing user to sync contacts as instagram is also of facebook. But what about twitter do you have any idea? – Grishma Ukani Sep 26 '17 at 04:32
  • if you google for "android twitter mimetype" you'll get `vnd.android.cursor.item/vnd.twitter.profile` i don't know if that's true, but sounds reasonable – marmor Sep 26 '17 at 04:42
  • what is the public profile url for twitter?if you know? – Grishma Ukani Sep 26 '17 at 07:42
  • @marmor I'm having the same issue in differentiating the MIMETYPEs of apps like WhatsApp, Duo. When I queried ContactsContract.Data table, I found `Message xxx`, `Video call xxx`, `Voice call xxx` of WhatsApp for a contact in `DATA3` column. However, for Duo I found the same in `DATA5` column. How do we know which column holds such values? Columns DATA1..DATA4 filled with some other data for Duo and DATA1..DATA2 are filled with something else for WhatsApp. – Karthik Jul 14 '20 at 04:56
  • How do you get this contact id I thought the contacts are being duplicated for every app and then linked and that's why I thought they have different contact ids – Chagai Friedlander Feb 01 '22 at 17:48