获取电子邮件使用自动完成TextView的联系方式?自动完成、电子邮件、联系方式、TextView

2023-09-06 13:15:23 作者:一炮到天亮

在我的应用程序,我有一个自动完成的TextView 的EditText 在此自动完成的TextView 提供的所有联系人的姓名从联系人。

In my application i've one AutoComplete TextView and EditText In this AutoComplete TextView provides all the contact names from Contacts.

我想获得该接触是在我的记忆式键入的TextView到EDITTEXT选择的主电子邮件ID。我怎样才能做到这一点?任何人指导我?

I want to get the primary email id which contact was selected in my AutoComplete Textview to the editText. How can i achieve this? Anyone guide me?

推荐答案

请确保您有您的应用程序 READ_CONTACTS 许可。

Make sure you have READ_CONTACTS permission for your App.

    AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
    Cursor emailCursor = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null, null, null);
    startManagingCursor(emailCursor);
    autoCompleteTextView.setAdapter(new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, emailCursor, new String[] {Email.DATA1}, new int[] {android.R.id.text1}));
    autoCompleteTextView.setThreshold(0);

请注意AutoCompleteTextView是区分大小写的。

Please Note AutoCompleteTextView is Case Sensitive.