Android的 - 让所有来自所有来源的联系人 [英] Android - Get All Contacts from All Sources

查看:158
本文介绍了Android的 - 让所有来自所有来源的联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图让一个Android应用程序,建立对2.0,这需要得到所有用户的联系人,并在一个格式化的方式显示它们。

I have been attempting to make an Android application, built against 2.0, that requires getting all of the user's contacts and displaying them in a formatted way.

我已经使用光标 ContactsContract.Contacts 类是能够得到一个列表。不过,名单我从供应商得到的只是给了我,无论是从用户的谷歌账户具有两个或多个源(如谷歌+脸谱,两Facebook账户等)的接触,或者接触。它并没有给我的整个列表。

I have been able to get a list using a Cursor and the ContactsContract.Contacts class. However, the list I get from that provider only gives me the contacts that are either from the user's Google account, or contacts that have two or more sources (e.g. Google + Facebook, Two Facebook accounts, etc). It does not give me the entire list.

那些似乎离开了主要是那些仅来自用户的Facebook帐户,并且没有其他来源

Those that seem left out are primarily those that come only from the user's Facebook account, and have no other source.

这是我使用的查询电话:

This is the query call I'm using:

Cursor contactsCursor = getContentResolver()
    .query(android.provider.ContactsContract.Contacts.CONTENT_URI, 
        null, null, null, null);

我的问题是是否有可能获得所有来自用户的电话簿中的每一个源(谷歌,Facebook等)的接触?

My question is is it possible to get all the contacts from every single source (Google, Facebook, etc) in the user's phonebook?

谢谢!

推荐答案

请参阅的ContactManager

OBS1:这code是使用德precated方法, managedQuery(),你需要重写这部分对使用code进行 android.content.CursorLoader

OBS1: this code is using an deprecated method, managedQuery() you will need to reimplement this part of the code using a android.content.CursorLoader.

OBS2: mShowInvisible - 如果真会列出所有的联系人,无论用户preference

OBS2: mShowInvisible - if true will list all contacts regardless of user preference

/**
 * Obtains the contact list for the currently selected account.
 *
 * @return A cursor for for accessing the contact list.
*/
private Cursor getContacts(){
    // Run query
    Uri uri = ContactsContract.Contacts.CONTENT_URI;
    String[] projection = new String[] {
        ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME
    };
    String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"(mShowInvisible ? "0" : "1") + "'";
    String[] selectionArgs = null;
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

    return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
}

这篇关于Android的 - 让所有来自所有来源的联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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