是否有特定联系人的联系电话或电子邮件选择器/选择器?

时间:2010-06-29 07:58:57

标签: android contacts

我有联系人,我希望用户可以从他的手机或电子邮件中进行选择。这是由一些选择者提供的还是我应该实现自己的?

1 个答案:

答案 0 :(得分:0)

试试这个

public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);
                startActivityForResult(intent, CONTACT_PICKER_RESULT);
            }
        });
    }

    @Override
    public void onActivityResult(int reqCode, int resultCode, Intent data) {
        super.onActivityResult(reqCode, resultCode, data);

        switch (reqCode) {
            case (CONTACT_PICKER_RESULT):
                if (resultCode == Activity.RESULT_OK) {
                    Uri contactData = data.getData();
                    Cursor c = managedQuery(contactData, null, null, null, null);
                    if (c.moveToFirst()) {
                        String name = c.getString(c.getColumnIndexOrThrow(People.NAME));
                        editTextRecipient.setText(name);
                    }
                }
                break;
        }
    }