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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:35:53+00:00 2026-05-19T00:35:53+00:00

I got most of the things working when querying contact data. I’m fighting with

  • 0

I got most of the things working when querying contact data. I’m fighting with StructuredName and Organization. They do not work for me.

If you don’t mind please have a look at the code. It’s handcrafted and lot of error checking is removed to make it as small as possible to be posted here. Comments with “not working” are the parts that don’t work for me.

The two leading if() are part of the onActivityResult where I receive the data at the end of the contact selection. Calling is done with:

intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, Main.DIALOG_PICKCONTACT);

Many thanks in advance
HJW

if (requestCode == Main.DIALOG_PICKCONTACT) {
 if (resultCode == RESULT_OK) {
  int i;
  String s;
  Cursor cursorContacts = managedQuery(intent.getData(),
      null,
      null,
      null,
      null);
  if (cursorContacts != null) {
   if (cursorContacts.moveToNext()) {
    ContentResolver contentResolver = getContentResolver();
    String contactId = cursorContacts.getString(cursorContacts.getColumnIndex(ContactsContract.Contacts._ID));
    i = cursorContacts.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
    // cursorContacts.getString(i); *** is DISPLAY_NAME
    Cursor cursorEmail = contentResolver.query(
        ContactsContract.CommonDataKinds.Email.CONTENT_URI,
        null,
        ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?",
        new String[] { contactId },
        null);
    if (cursorEmail != null) {
     while (cursorEmail.moveToNext()) {
      int type = cursorEmail.getInt(cursorEmail.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE));
      s = cursorEmail.getString(cursorEmail.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
      switch (type) {
       case ContactsContract.CommonDataKinds.Email.TYPE_HOME:
        // s *** is private Email
        break;
       case ContactsContract.CommonDataKinds.Email.TYPE_WORK:
        // s *** is business Email
        break;
      }
     }
     cursorEmail.close();
    }
    Cursor cursorOrganization = contentResolver.query(
        ContactsContract.Data.CONTENT_URI,
        null,
        ContactsContract.CommonDataKinds.Organization.CONTACT_ID + " = ?",
        new String[] { contactId },
        null);
    if (cursorOrganization != null) {
     if (cursorOrganization.moveToNext()) {
      s = cursorOrganization.getString(cursorOrganization.getColumnIndex(ContactsContract.CommonDataKinds.Organization.DATA));
      // s *** Company name not working
      s = cursorOrganization.getString(cursorOrganization.getColumnIndex(ContactsContract.CommonDataKinds.Organization.TITLE));
      // s *** Function within company not working
     }
     cursorOrganization.close();
    }
    s = cursorContacts.getString(cursorContacts.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
    if (Integer.parseInt(s) > 0) {
     Cursor cursorPhone = contentResolver.query(
         ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
         null,
         ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
         new String[] { contactId },
         null);
     if (cursorPhone != null) {
      while (cursorPhone.moveToNext()) {
       int type = cursorPhone.getInt(cursorPhone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
       s = cursorPhone.getString(cursorPhone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
       switch (type) {
        case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_HOME:
         // s *** is private fax
         break;
        case ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK:
         // s *** is business fax
         break;
        case ContactsContract.CommonDataKinds.Phone.TYPE_HOME:
         // s *** is private phone
         break;
        case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
         // s *** is mobile phone
         break;
        case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
         // s *** is business phone
         break;
        case ContactsContract.CommonDataKinds.Phone.TYPE_WORK_MOBILE:
         // s *** is business mobile
         break;
       }
      }
      cursorPhone.close();
     }
    }
    Cursor cursorStructuredName = contentResolver.query(
        ContactsContract.Data.CONTENT_URI,
        null,
        ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID + " = ?",
        new String[] { contactId },
        null);
    if (cursorStructuredName != null) {
     if (cursorStructuredName.moveToNext()) {
      i = cursorStructuredName.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME);
      // cursorStructuredName.getString(i); *** given name not working
      i = cursorStructuredName.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME);
      // cursorStructuredName.getString(i); *** middle name not working
      i = cursorStructuredName.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.PREFIX);
      // cursorStructuredName.getString(i); *** prefix not working
      i = cursorStructuredName.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.SUFFIX);
      // cursorStructuredName.getString(i); *** suffix not working
     }
     cursorStructuredName.close();
    }
    Cursor cursorStructuredPostal = contentResolver.query(
        ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI,
        null,
        ContactsContract.CommonDataKinds.StructuredPostal.CONTACT_ID + " = ?",
        new String[] { contactId },
        null);
    if (cursorStructuredPostal != null) {
     while (cursorStructuredPostal.moveToNext()) {
      int type = cursorStructuredPostal.getInt(cursorStructuredPostal.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.TYPE));
      s = cursorStructuredPostal.getString(cursorStructuredPostal.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY));
      switch (type) {
       case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME:
        //s *** is private country
        break;
       case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK:
        // s *** is business country
        break;
      }
      s = cursorStructuredPostal.getString(cursorStructuredPostal.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY));
      switch (type) {
       case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME:
        // s *** is private city
        break;
       case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK:
        // s *** is business city
        break;
      }
      s = cursorStructuredPostal.getString(cursorStructuredPostal.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE));
      switch (type) {
       case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME:
        // s *** is private postcode
        break;
       case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK:
        // s *** is business postcode
        break;
      }
      s = cursorStructuredPostal.getString(cursorStructuredPostal.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET));
      switch (type) {
       case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME:
        // s *** is private street
        break;
       case ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK:
        // s *** is business street
        break;
      }
     }
     cursorStructuredPostal.close();
    }
    Cursor cursorWebsite = contentResolver.query(
        ContactsContract.Data.CONTENT_URI,
        null,
        ContactsContract.CommonDataKinds.Website.CONTACT_ID + " = ?",
        new String[] { contactId },
        null);
    if (cursorWebsite != null) {
     while (cursorWebsite.moveToNext()) {
      i = cursorWebsite.getColumnIndex(ContactsContract.CommonDataKinds.Website.URL);
      int type = cursorWebsite.getColumnIndex(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
      s = cursorWebsite.getString(i);
      switch (type) {
       case ContactsContract.CommonDataKinds.Website.TYPE_HOME:
        // s *** private url not working
        break;
       case ContactsContract.CommonDataKinds.Website.TYPE_WORK:
        // s *** business url not working
        break;
      }
     }
     cursorWebsite.close();
    }
   }
   cursorContacts.close();
  }
 }
}
  • 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-19T00:35:54+00:00Added an answer on May 19, 2026 at 12:35 am

    Your where condition is wrong.

    Use this for StructuredName:

        // projection
        String[] projection = new String[] {ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME};
    
    
        String where = ContactsContract.Data.RAW_CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; 
        String[] whereParameters = new String[]{this.contact_id, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE};
    
        //Request
        Cursor contacts = this.resolver.query(ContactsContract.Data.CONTENT_URI, projection, where, whereParameters, null);
    
        //Iteration
        if (contacts.moveToFirst()) { 
            //code here
        } 
        contacts.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm testing a recent WCF Data Service that I've set. Most of things are
I've got a universal iOS app that I've been working on. For the most
Noobie muddling his way through an Ajax autosuggest form: I've got most of it
I'm hoping someone can help me with a backbone.js question. I've got most of
We've got a multi-agent Java environment where different agent would most likely produce all
I've got an issue with an ASP.Net MVC project in that on most of
With lots of efforts and tutorials I got xdebug/wincachegrind up and running but most
I'll let this jsfiddle describe most of the problem for me. http://jsfiddle.net/zAPVQ/4/ I've got
HTML is <tr> <td><input /></td> <td><a>ref</a></td> </tr> I got $('a') What is the most
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)

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.