如何从联系人列表获取联系人姓名,号码和鄂麦ID? [英] How to Get Contact name, number and emai ID from a list of contacts?

查看:142
本文介绍了如何从联系人列表获取联系人姓名,号码和鄂麦ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人,我需要让我接触的细节,但细节只包括3

I am new to android ,I need to get the details of my contacts, but the details include only 3

  1. 联系人姓名

  1. Contact name

联系电话以及

电子邮件ID

当我preSS一个按钮,它会告诉我的所有联系人这3细节

when I press a Button it will show these 3 details of my all contacts

我使用的Andr​​oid 2.1埃克莱尔版本。任何解决方案?

I am using android Eclair version 2.1. Any solution ?

推荐答案

通过code以下,你可以做到这一点 -

By below code you can do that -

public void doLaunchContactPicker(View view) {
    Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,Contacts.CONTENT_URI);
    startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    if (resultCode == RESULT_OK) {
        switch (requestCode) 
        {
        case CONTACT_PICKER_RESULT:
            Cursor cursor = null;
            String email = "", name = "";
            try {
                Uri result = data.getData();
                Log.v(DEBUG_TAG, "Got a contact result: " + result.toString());

                // get the contact id from the Uri
                String id = result.getLastPathSegment();

                // query for everything email
                cursor = getContentResolver().query(Email.CONTENT_URI,  null, Email.CONTACT_ID + "=?", new String[] { id }, null);

                int nameId = cursor.getColumnIndex(Contacts.DISPLAY_NAME);

                int emailIdx = cursor.getColumnIndex(Email.DATA);

                // let's just get the first email
                if (cursor.moveToFirst()) {
                    email = cursor.getString(emailIdx);
                    name = cursor.getString(nameId);
                    Log.v(DEBUG_TAG, "Got email: " + email);
                } else {
                    Log.w(DEBUG_TAG, "No results");
                }
            } catch (Exception e) {
                Log.e(DEBUG_TAG, "Failed to get email data", e);
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
                EditText emailEntry = (EditText) findViewById(R.id.editTextv);
                EditText personEntry = (EditText) findViewById(R.id.person);
                emailEntry.setText(email);
                personEntry.setText(name);
                if (email.length() == 0 && name.length() == 0) 
                {
                    Toast.makeText(this, "No Email for Selected Contact",Toast.LENGTH_LONG).show();
                }
            }
            break;
        }

    } else {
        Log.w(DEBUG_TAG, "Warning: activity result not ok");
    }
}

和,也请参阅以下链接 -

And, also refer these links -

  1. 获取联系方式

如何阅读联系人

得到的所有联系方式

不要忘记添加所需的权限 -

Don't forget to add the required permission -

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

的Andr​​oidManifest.xml 文件。而且,只需修改此code与您的需求。

in your AndroidManifest.xml file. And, Just modify this code with your needs.

这篇关于如何从联系人列表获取联系人姓名,号码和鄂麦ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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