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 6029097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:50:10+00:00 2026-05-23T04:50:10+00:00

I am getting phone no’s, mails from contacts with out extends activity and oncreate

  • 0

I am getting phone no’s, mails from contacts with out extends activity and oncreate method.

By using the fallowing code:

 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
          Class A extends Activity{

  new ClassB(this);
 }

 ////////////////////////////////////////////////////
 public static void getContactNumbers(Context context) {
    String contactNumber = null;
    int contactNumberType = Phone.TYPE_MOBILE;
    String nameOfContact = null;

        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));
                        Log.i(TAG, "...Contact Name ...." + nameOfContact
                                + "...contact Number..." + contactNumber);
                        ApplicationConstants.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;


        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));
                    ApplicationConstants.emailContacts
                            .add(new ContactEmailBean(contactName,
                                    emailIdOfContact, emailType));

                }
                emails.close();

            }
        }// end of contact name cursor
        cur.close();


} 

/////////////////////////////////////////

It is working fine from getting results but I don’t know how to implement the fallowing code in the above example:

ApplicationConstants.phoneContacts
.add(new ContactNumberBean(nameOfContact,
contactNumber, contactNumberType));

If any one know this please help me.

  • 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-23T04:50:11+00:00Added an answer on May 23, 2026 at 4:50 am

    You only need access to an android.content.Context object to access the ContentResolver and thus query ContentProviders. Activity extends Context, so that works. android.app.Service also extends Activity, so that works too. android.app.Application also extends Context, so that will work too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting contact details for a given phone number using the following code:
Is there a method for getting the iPhone users phone number using HTML5/jQuery? All
i have use this code for getting pictures from Phone's memory... TFileName path =
Exact Duplicate of: Getting the size (free,total) of a Windows Mobile phone drive using
Using the Facebook API, is there a way of getting a friend's phone/cell number?
I am trying to put Name and phone numbers from contacts to my customized
I am looking at getting a smart-phone most likely from at&t(current provider) and I
I am having trouble getting phone numbers from the iPhone Addressbook. There is no
I'm currently working with getting a phone number from a JtextField, the problem i'm
Is there a way of getting all the phone numbers for all contacts without

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.