如何从android 1.6中的联系人中获取电子邮件ID?

发布于 2024-10-18 13:19:48 字数 112 浏览 0 评论 0原文

你好 我正在开发一个基于联系人的应用程序,因为我想从联系人中获取电子邮件 ID 到我的应用程序

我正在为 android 1.6 开发应用程序

请任何人帮助我做到这一点。提前致谢

Hi
I am developing a contact based application in that i want get the email id from the contacts to my application

I am developing the application for android 1.6

Please any on help me to do that.Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

メ斷腸人バ 2024-10-25 13:19:48

您可以参考此链接 http://thinkandroid.wordpress.com/2010/01/19/retriving-contact-information-name-number-and-profile-picture/

找到行 String[] columns = new String[ ] { People.NAME, People.NUMBER };
您可以使用此 http://developer.android.com/参考/android/provider/Contacts.People.html#PRIMARY_EMAIL_ID

获取电子邮件 ID。我对此不确定,但是是的,你可以尝试一下

You can refer to this link http://thinkandroid.wordpress.com/2010/01/19/retrieving-contact-information-name-number-and-profile-picture/

find the line String[] columns = new String[] { People.NAME, People.NUMBER };
and you can use this http://developer.android.com/reference/android/provider/Contacts.People.html#PRIMARY_EMAIL_ID

to get email id. I am not sure on this but yes you can give it a try

长安忆 2024-10-25 13:19:48
ContentResolver cr = getContentResolver();
            Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                    null, null, null);
            int index = 0;

            if (cur.getCount() > 0) {

                emailNames = new String[cur.getCount()];
                emailNumbers = new String[cur.getCount()];

                while (cur.moveToNext()) {
                    String id = cur.getString(cur
                            .getColumnIndex(ContactsContract.Contacts._ID));
                    name = cur
                            .getString(cur
                                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                    emailNames[index] = name;

                    Cursor emails = getContentResolver().query(
                            ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Email.CONTACT_ID
                                    + " = " + id, null, null);
                    while (emails.moveToNext()) {
                        // This would allow you get several email addresses
                        String emailAddress = emails
                                .getString(emails
                                        .getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                        Log.v("email==>", emailAddress);


                            emailNumbers[index] = emailAddress;

                        }
                    }
                    emails.close();
                    index++;

                }
                cur.close();
ContentResolver cr = getContentResolver();
            Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                    null, null, null);
            int index = 0;

            if (cur.getCount() > 0) {

                emailNames = new String[cur.getCount()];
                emailNumbers = new String[cur.getCount()];

                while (cur.moveToNext()) {
                    String id = cur.getString(cur
                            .getColumnIndex(ContactsContract.Contacts._ID));
                    name = cur
                            .getString(cur
                                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                    emailNames[index] = name;

                    Cursor emails = getContentResolver().query(
                            ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Email.CONTACT_ID
                                    + " = " + id, null, null);
                    while (emails.moveToNext()) {
                        // This would allow you get several email addresses
                        String emailAddress = emails
                                .getString(emails
                                        .getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                        Log.v("email==>", emailAddress);


                            emailNumbers[index] = emailAddress;

                        }
                    }
                    emails.close();
                    index++;

                }
                cur.close();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文