Monday, August 8, 2011

[android-developers] Re: Android goolge contact fetch

You can't look up groups with ContactsContract.Contacts.CONTENT_URI.
As docs for ContactsContract.CommonDataKinds states: "Container for
definitions of common data types stored in the ContactsContract.Data"
table. So your query should look like

contentresolver.managedQuery(ContactsContract.Data.CONTENT_URI,
projection,
Data.MIMETYPE + "='" +
CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE + "' AND " +
CommonDataKinds.GroupMembership.GROUP_ROW_ID + "=" + groupid, ...

Note the single quotes around the group membership type and the single
'='. Remember, SQL syntax is used here.
See http://developer.android.com/reference/android/provider/ContactsContract.Data.html
for more info.
Also, I recommend using managedQuery(). If you use query(), you need
to close the cursor after you are done with it or you will leak memory
when your cursor variable is reused on the next query (Android really
isn't Java ;-)).

On Aug 8, 10:14 am, Goutom <goutom.sust....@gmail.com> wrote:
> Hi All
>
> I want to fetch all goolge contact of a group by group id.Here is my code.
>
>     public ArrayList<T> Get_Contact_Info(String groupid, String groupname) {
>
>         ArrayList<Contact_Content> contactlist = new
> ArrayList<Contact_Content>();
>         String[] projection = new String[] {
>
>                 ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID,
>                 ContactsContract.CommonDataKinds.GroupMembership.STARRED,
>
> ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME};
>
>         Cursor contacts =
> contentresolver.query(ContactsContract.Contacts.CONTENT_URI, projection,
>
> ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID
>                         + " =='" + groupid + "'", null,
>
> ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME
>                         + " COLLATE LOCALIZED ASC");
>
>         while (contacts.moveToNext()) {
>
> }
>
> Here "groupid" is the id of a group which I am generating by another query.
> When I debug, red lines red lines stops my programmer.Can anyone check the
> code plz?
>
> 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