how to get all social accounts linked with the particular contact in android from phonebook?
Asked Answered
S

1

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.

Slumlord answered 20/9, 2017 at 6:8 Comment(5)
Are you asking about looking up contacts on those services? So, sending the email to Twitter to see what the user name is?Hulky
No, i am fetching the contacts from phonebook. Now i want accounts linked with those contacts.Ex.(LinkedIn,Facebook,Instagram,Twitter).Slumlord
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?Shwalb
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.Slumlord
@Shwalb Hi i have update the question with the screenshot of the info i want to query.Slumlord
S
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

Shwalb answered 25/9, 2017 at 11:19 Comment(8)
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 urlSlumlord
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?Slumlord
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.Shwalb
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?Slumlord
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 reasonableShwalb
what is the public profile url for twitter?if you know?Slumlord
@Shwalb 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.Dovelike
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 idsAdila

© 2022 - 2024 — McMap. All rights reserved.