[android-developers] Re: contacts first and last name
_ID in data table and contacts table are two different things. So you
should use raw_contacts_id instead of _id when query in data table.
change
String[] projection = new String[]
{ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,ContactsContrac
t.CommonDataKinds.StructuredName.FAMILY_NAME};
String where = ContactsContract.CommonDataKinds.StructuredName._ID+ "
= ?
AND "+ ContactsContract.CommonDataKinds.StructuredName.MIMETYPE+ "
= ?";
to
String[] projection = new String[]
{ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,ContactsContrac
t.CommonDataKinds.StructuredName.FAMILY_NAME};
String where = ContactsContract.Data.CONTACT_ID " = ?
AND "+ ContactsContract.CommonDataKinds.StructuredName.MIMETYPE+ "
= ?";
On 11月5日, 上午7时38分, Goutom <goutom.sust....@gmail.com> wrote:
> Hi
>
> I am trying to fetch contacts first and last name.But getting fail.
> I am using the following code.
>
> String id;
> String[] projection = new String[]
> {ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,ContactsContrac t.CommonDataKinds.StructuredName.FAMILY_NAME};
> String where = ContactsContract.CommonDataKinds.StructuredName._ID+ " = ?
> AND "+ ContactsContract.CommonDataKinds.StructuredName.MIMETYPE+ " = ?";
>
> id = Get_Id(contact_id);
> String[] whereParameters = new String[]
> {id,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE };
> Cursor cursor =
> cr.query(ContactsContract.Data.CONTENT_URI,projection, where,
> whereParameters, null);
>
> if(cursor.moveToFirst())
> {
> String contact_given_name =
> cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Str ucturedName.GIVEN_NAME));
> String contact_family_name =
> cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Str ucturedName.FAMILY_NAME));
> }
> cursor.close();
> but its giving null. where is the problem?
>
> Take care.
>
> Regards
> Goutom Roy
--
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
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home