How to get all social accounts associated with a specific contact in android from the phone book?

I selected all the device contacts from the phone book. Now I want to get related accounts (facebook, twitter, instagram, LinkedIn) from this particular contact that is called from the phone book. What should I do?

Here is the code to retrieve 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 get accounts (e.g. facebook, linkedin, etc.) associated with a specific contact .

Can anybody help me.

Update: In the attached image below, clicking on the section highlighted in red opens the linked one in the user's profile in the browser. Therefore, I want to get a field that is used to open the user profile page.

enter image description here

.

+6
2

MIMETYPE , , , Google+ MIMETYPE: vnd.android.cursor.item/vnd.googleplus.profile

MIMETYPE , :

// 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();

MIMETYPE, , :

// 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:

inimimype : vnd.android.cursor.item/vnd.com.linkedin.android.profile. , URL- , Data1 , AC...UQ4 ( 40 ).

URL-: https://www.linkedin.com/profile/view?id=<data1Id> : https://www.linkedin.com/profile/view?id=AC...UQ4

+3

.

ArrayList<String> accountsInfo = new ArrayList<String>();
    AccountManager manager = AccountManager.get(this);
    Account[] accounts = manager.getAccounts();
    for (Account account : accounts) {
        String name = account.name;
        String type = account.type;
        int describeContents = account.describeContents();
        int hashCode = account.hashCode();

        accountsInfo.add("name = " + name +
                         "\ntype = " + type +
                         "\n");
    }
    String[] result = new String[accountsInfo.size()];
    accountsInfo.toArray(result);

.

    /**
     * com.facebook.auth.login /
     * com.linkedin.android
     * flipkart.com
     * com.facebook.messenger
     * com.twitter.android.auth.login
     * com.truecaller.account
     * net.one97.paytm
     * com.whatsapp
     * com.google
     */

    Cursor c = getContentResolver().query(
            ContactsContract.RawContacts.CONTENT_URI,
            new String[]{ContactsContract.RawContacts.CONTACT_ID, ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY},
            ContactsContract.RawContacts.ACCOUNT_TYPE + "= ?",
            new String[]{"com.whatsapp"},
            null);

    final ArrayList<String> myContacts = new ArrayList<String>();
    int contactNameColumn = c.getColumnIndex(ContactsContract.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));
    }
    Log.d("contact size", String.valueOf(myContacts.size()));
+1

All Articles