Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5983969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:18:26+00:00 2026-05-22T22:18:26+00:00

hi all how to implement coding for get email id’s from contacts and get

  • 0

hi all how to implement coding for get email id’s from contacts and get phone no from contacts show me the way to overcome from this problem
note: class doesn’t have extends Activity and oncreate() method also so kindly help me to go forward

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:18:26+00:00Added an answer on May 22, 2026 at 10:18 pm

    Your class doesnot have extends Activity or onCreate() method. So pass the context parameter from the class which extends Activity to this class.

    sudo code

    Class A extends Activity{
    
    new ClassB(this);
    }
    

    here Class B does not extends Activity.
    But write the following method to gwt contacts and email id in class B

    public static void getContactNumbers(Context context) {
        String contactNumber = null;
        int contactNumberType = Phone.TYPE_MOBILE;
        String nameOfContact = null;
        ArrayList<ContactNumberBean> phoneContacts = new ArrayList<ContactNumberBean>();
            ContentResolver cr = context.getContentResolver();
            Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                    null, null, null);
            if (cur.getCount() > 0) {
                while (cur.moveToNext()) {
                    String id = cur.getString(cur
                            .getColumnIndex(BaseColumns._ID));
                    nameOfContact = cur
                            .getString(cur
                                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
    
                    if (Integer
                            .parseInt(cur.getString(cur
                                    .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                        Cursor phones = cr
                                .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                        null,
                                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                                + " = ?", new String[] { id },
                                        null);
    
                        while (phones.moveToNext()) {
                            contactNumber = phones.getString(phones
                                    .getColumnIndex(Phone.NUMBER));
                            contactNumberType = phones.getInt(phones
                                    .getColumnIndex(Phone.TYPE));
    
                            phoneContacts
                                    .add(new ContactNumberBean(nameOfContact,
                                            contactNumber, contactNumberType));
                        }
                        phones.close();
                    }
    
                }
            }// end of contact name cursor
            cur.close();
    
    }
    
    /**
     * 
     * This method is responsible to get native contacts and corresponding email
     * id (ApplicationConstants.emailContacts)
     * 
     * @param context
     */
    public static void getContactEmails(Context context) {
        String emailIdOfContact = null;
        int emailType = Email.TYPE_WORK;
        String contactName = null;
        ArrayList<ContactEmailBean> emailContacts = new ArrayList<ContactEmailBean>();
    
    
    
            ContentResolver cr = context.getContentResolver();
            Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
                    null, null, null);
            if (cur.getCount() > 0) {
                while (cur.moveToNext()) {
                    String id = cur.getString(cur
                            .getColumnIndex(BaseColumns._ID));
                    contactName = cur
                            .getString(cur
                                    .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                    // Log.i(TAG,"....contact name....." +
                    // contactName);
    
                    cr.query(
                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                    + " = ?", new String[] { id }, null);
    
                    Cursor emails = cr.query(Email.CONTENT_URI, null,
                            Email.CONTACT_ID + " = " + id, null, null);
                    while (emails.moveToNext()) {
                        emailIdOfContact = emails.getString(emails
                                .getColumnIndex(Email.DATA));
                        // Log.i(TAG,"...COntact Name ...."
                        // + contactName + "...contact Number..."
                        // + emailIdOfContact);
                        emailType = emails.getInt(emails
                                .getColumnIndex(Phone.TYPE));
                        emailContacts
                                .add(new ContactEmailBean(contactName,
                                        emailIdOfContact, emailType));
    
                    }
                    emails.close();
    
                }
            }// end of contact name cursor
            cur.close();
    
    
    }
    

    Write two bean class

    EmailBean

    public class ContactEmailBean {
            String emailType = null;
            String nameOfContact = null;
    
            String emailIdOfContact = null;
    
            public ContactEmailBean(String nameOfContact, String emailIdOfContact,
                    int emailType) {
                switch (emailType) {
                case Email.TYPE_HOME:
                    this.emailType = "HOME";
                    // do something with the Home number here...
                    break;
                case Email.TYPE_MOBILE:
                    this.emailType = "MOBILE";
                    // do something with the Mobile number here...
                    break;
                case Email.TYPE_WORK:
                    this.emailType = "WORK";
                    // do something with the Work number here...
                    break;
    
                default:
                    this.emailType = "OTHER";
                    break;
                }
                this.nameOfContact = nameOfContact;
                this.emailIdOfContact = emailIdOfContact;
    
            }
    
            public String getNameOfContact() {
                return this.nameOfContact;
            }
    
            public String getEmailType() {
                return this.emailType;
            }
    
            public String getEmailIdOfContact() {
                return this.emailIdOfContact;
            }
        }
    

    ContactNumberBean

    public class ContactNumberBean {
            String phoneNumberType = null;
            String nameOfContact = null;
            String contactNumber = null;
    
            public ContactNumberBean(String nameOfContact, String contactNumber,
                    int contactNumberType) {
                switch (contactNumberType) {
                case Phone.TYPE_HOME:
                    this.phoneNumberType = "HOME";
                    // do something with the Home number here...
                    break;
                case Phone.TYPE_MOBILE:
                    this.phoneNumberType = "MOBILE";
                    // do something with the Mobile number here...
                    break;
                case Phone.TYPE_WORK:
                    this.phoneNumberType = "WORK";
                    // do something with the Work number here...
                    break;
                case Phone.TYPE_WORK_MOBILE:
                    this.phoneNumberType = "WORK";
                    break;
    
                case Phone.TYPE_FAX_HOME:
                    this.phoneNumberType = "FAX";
                    break;
                default:
                    this.phoneNumberType = "OTHER";
                    break;
                }
                this.nameOfContact = nameOfContact;
                this.contactNumber = contactNumber;
    
            }
    
            public String getNameOfContact() {
                return this.nameOfContact;
            }
    
            public String getPhoneNumberType() {
                return this.phoneNumberType;
            }
    
            public String getContactNumber() {
                return this.contactNumber;
            }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way/tool that could show me all the classes/interfaces that implement a
Using reflection, how can I get all types that implement an interface with C#
We need to get all the instances of objects that implement a given interface
Is there a way to find all web pages that implement a specific master
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
If have a set of classes that all implement an interface. interface IMyinterface<T> {
I have developed some classes with similar behavior, they all implement the same interface.
All I am currently trying implement something along the lines of dim l_stuff as
trying to implement a dialog-box style behaviour using a separate div section with all
I think the title pretty much says it all... I'm looking to implement an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.