如何让用户从设备的联系人列表中的连接? [英] How to get the connectivity of user from contact list of device?

查看:116
本文介绍了如何让用户从设备的联系人列表中的连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能获得设备的联系人列表中任何联系人的连接?像谷歌+帐户,和其他第三方API的电子邮件ID连接,我正在寻找它的查询。但没有得到妥善解决。所以请朋友们帮我把这些问题理清。在此先感谢

Is it possible to get the connections of any contact from contact list of device? Connection like email id of google+ account, and other third party api,I am searching the query of it. But did not get the proper solution. So please friends help me to sort out from these problem. Thanks in advance

推荐答案

在联系人提供商,该联系人的连接只是所有的 RawContacts 该特定<一个href=\"https://developer.android.com/reference/android/provider/ContactsContract.RawContactsColumns.html#CONTACT_ID\"相对=nofollow> CONTACT_ID 。而他们的数据存储在 数据 表。

In the Contacts provider, the "connections" of a Contact are just all the entries in RawContacts for that particular CONTACT_ID. And their data is stored in the Data table.

因此​​,让所有的联系人的所有连接的信息,这足以查询数据表具有适当的过滤器。例如:

Therefore, to get all the info on all the connections of a contact, it's enough to query the Data table with the appropriate filter. For example:

private static void getConnections(Context context, int contactId)
{
    // Read all data for contactId
    String selection = RawContacts.CONTACT_ID + " = ?";
    String[] selectionArgs = new String[] { String.valueOf(contactId) };

    Cursor c = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, selection, selectionArgs, null);
    while (c.moveToNext())
    {
        String accountType = c.getString(c.getColumnIndexOrThrow(ContactsContract.RawContacts.ACCOUNT_TYPE));
        String accountName = c.getString(c.getColumnIndexOrThrow(ContactsContract.RawContacts.ACCOUNT_NAME));
        String dataMimeType = c.getString(c.getColumnIndexOrThrow(ContactsContract.Data.MIMETYPE));
        String dataValue = c.getString(c.getColumnIndexOrThrow(ContactsContract.Data.DATA1));

        Log.d("contactInfo", accountName + " (" + accountType + ") - " + dataMimeType + " - " + dataValue);
    }

    c.close();
}

您可以通过使用更严格的选择筛选此数据 / selectionArgs两个参数(如针对特定 ACCOUNT_TYPE MIMETYPE ,等等)。

You can filter this data by using more restrictive selection / selectionArgs arguments (such as for a specific ACCOUNT_TYPE, MIMETYPE, and so forth).

当然,你需要在AndroidManifest.xml的相应权限:

Of course, you need the appropriate permission in AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_CONTACTS" />

这篇关于如何让用户从设备的联系人列表中的连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆