Monday, August 8, 2011

[android-developers] Google contact name fetch

Hi All

Can any one check the code plz. where is my problem? I want to fetch name of a contact by its id.I am new to android.I dont understand the error in logcat.
 
    public void Get_Contact_Name(String id)
    {
// "id" is the contact id which I am fetching from another method.

        String[] projection = new String[] {ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
                ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
                ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,
                ContactsContract.CommonDataKinds.StructuredName.SUFFIX,
                ContactsContract.CommonDataKinds.StructuredName.PREFIX,
                ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME};

       String where =  ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID + " = ?" ; //problem may be here
        String[] whereParameters = new String[]{id};  //problem may be here

   

        Cursor contacts = contentresolver.query(ContactsContract.Data.CONTENT_URI, projection, where, whereParameters, null); //problem may be here
        if (contacts.moveToFirst()) {
            contactcontent.contact_display_name = contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME));
            contactcontent.contact_given_name =contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
            contactcontent.contact_suffix_name = contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.SUFFIX));
            contactcontent.contact_prefix_name = contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.PREFIX));
            contactcontent.contact_middle_name = contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME));
            contactcontent.contact_family_name = contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
        }
        contacts.close();

    }

Thanks in advance.
Regards
Goutom

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment