Android 使用Intent.ACTION\u PICK时是否可以排除SIM卡联系人?

Android 使用Intent.ACTION\u PICK时是否可以排除SIM卡联系人?,android,android-intent,android-contacts,Android,Android Intent,Android Contacts,我需要在我的应用程序中选择联系人,并希望排除SIM卡中存储的联系人。使用操作\u PICK可以吗?不,不可能 不幸的是,现在还不可能 为了证明这一点,让我们深入研究的源代码 活动的onCreate()方法。在其中,ContactApp读取我们传递给它并分别处理的Intent(ACTION\u PICK): @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); mIconSize =

我需要在我的应用程序中选择联系人,并希望排除SIM卡中存储的联系人。使用
操作\u PICK
可以吗?

不,不可能 不幸的是,现在还不可能

为了证明这一点,让我们深入研究源代码
活动的
onCreate()
方法。在其中,ContactApp读取我们传递给它并分别处理的
Intent
ACTION\u PICK
):

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mIconSize = getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
    mContactsPrefs = new ContactsPreferences(this);
    mPhotoLoader = new ContactPhotoLoader(this, R.drawable.ic_contact_list_picture);

    // Resolve the intent
    final Intent intent = getIntent();

    // Allow the title to be set to a custom String using an extra on the intent
    String title = intent.getStringExtra(UI.TITLE_EXTRA_KEY);
    if (title != null) {
        setTitle(title);
    }

    String action = intent.getAction();
    String component = intent.getComponent().getClassName();

    // When we get a FILTER_CONTACTS_ACTION, it represents search in the context
    // of some other action. Let's retrieve the original action to provide proper
    // context for the search queries.
    if (UI.FILTER_CONTACTS_ACTION.equals(action)) {
        mSearchMode = true;
        mShowSearchSnippets = true;
        Bundle extras = intent.getExtras();
        if (extras != null) {
            mInitialFilter = extras.getString(UI.FILTER_TEXT_EXTRA_KEY);
            String originalAction =
                    extras.getString(ContactsSearchManager.ORIGINAL_ACTION_EXTRA_KEY);
            if (originalAction != null) {
                action = originalAction;
            }
            String originalComponent =
                    extras.getString(ContactsSearchManager.ORIGINAL_COMPONENT_EXTRA_KEY);
            if (originalComponent != null) {
                component = originalComponent;
            }
        } else {
            mInitialFilter = null;
        }
    }

    Log.i(TAG, "Called with action: " + action);
    mMode = MODE_UNKNOWN;
    if (UI.LIST_DEFAULT.equals(action) || UI.FILTER_CONTACTS_ACTION.equals(action)) {
        ..... 
        else if (Intent.ACTION_PICK.equals(action)) {
        // XXX These should be showing the data from the URI given in
        // the Intent.
        final String type = intent.resolveType(this);
        if (Contacts.CONTENT_TYPE.equals(type)) {
            mMode = MODE_PICK_CONTACT;
        } else if (People.CONTENT_TYPE.equals(type)) {
            mMode = MODE_LEGACY_PICK_PERSON;
        } else if (Phone.CONTENT_TYPE.equals(type)) {
            mMode = MODE_PICK_PHONE;
        } else if (Phones.CONTENT_TYPE.equals(type)) {
            mMode = MODE_LEGACY_PICK_PHONE;
        } else if (StructuredPostal.CONTENT_TYPE.equals(type)) {
            mMode = MODE_PICK_POSTAL;
        } else if (ContactMethods.CONTENT_POSTAL_TYPE.equals(type)) {
            mMode = MODE_LEGACY_PICK_POSTAL;
        }
       ....
       // VERY LONG IF WITH DIFFERENT MODE-SELECTION
       ....
    }
    .....
    if (mMode == MODE_JOIN_CONTACT) {
        setContentView(R.layout.contacts_list_content_join);
    } else if (mSearchMode) {
        setContentView(R.layout.contacts_search_content);
    } else if (mSearchResultsMode) {
        setContentView(R.layout.contacts_list_search_results);
    } else {
        setContentView(R.layout.contacts_list_content);
    }

    setupListView();
    ...
}
这是一个非常长的方法(我也建议检查方法),但非常简单。而且,正如您所看到的,您无法传递任何参数来指定要从中选择的联系人的来源。这里唯一可以配置的是要使用的特定的
mMode
联系人(
MODE\u-PICK\u-CONTACT
MODE\u-PICK\u-PHONE
,等等)-但不幸的是,可能的模式数量非常有限,只有6种,其中没有一种适合您

(如果任何人需要将
mMode
传递到
ContanctsListActivity
-请使用intent的
setType()
方法,例如:
intent.setType(contacts.commondatatypes.Phone.CONTENT_TYPE);

变通办法 作为一种解决方法,正如tiny sunlight在评论中建议的那样,在应用程序中呈现非SIM卡联系人,并从中选择所需联系人。
-这个链接看起来是最有希望的一个,它解释了除了SIM卡之外,如何查询所有联系人的游标


我希望,这有助于检查此链接:您应该使用Contacts contract.Contacts.CONTENT\u URI查询并在自己的列表视图中显示它们。