Hello

I am working in an android application where I want to fetch all the gmail
contacts of a account of a android phone.
I tried it many ways but it takes too many times to fetch just of a 28
contacts.I want to fetch:

1.organization name of TYPE_WORK
2.organization city name of TYPE_WORK
3.organization state name of TYPE_WORK
4.organization street name of TYPE_WORK
5. phone number of TYPE_WORK
6. email address of TYPE_WORK
7.etc......

I need to fetch these when the app is started.So I need fast calculation.

My code is here: this is small portion of my code.


----------------------------------- start
-----------------------------------------------------------------


public void FetchContacts(String gid) // "gid" is the group id of a account(
[email protected]), I am fetching group id of a account from another method.
{
String[] pro = new String[] {
ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID,
ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME};
 Cursor contacts =
cr.query(ContactsContract.Data.CONTENT_URI,pro,ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID+
" =='" + gid + "'", null,ContactsContract.Contacts.DISPLAY_NAME+ " COLLATE
LOCALIZED ASC");
 while (contacts.moveToNext()) {
try {
String contact_id  =
contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID));
 String contact_display_name =
contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME));
String contact_phone = Get_PhoneNumber_TYPE_WORK(contact_id);
 } catch (Exception ex) {
ex.printStackTrace();
 }
}
}

public String Get_PhoneNumber_TYPE_WORK(String id)
{
    String[] pro = new String[]
{ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.TYPE};
        Cursor pCur =
cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,pro,ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+" = ?",new String[]{id}, null);
    String type;
    while (pCur.moveToNext()) {
    type =
Null_check(pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)));
     if (type.equals("3")) { // here "3" is TYPE_WORK
    return
Null_check(pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
    break;
    }
    }
    pCur.close();
}


----------------------------------------------- end
------------------------------------------------------------------------------

I want to fetch these data by a single query, I think then it will not take
long time to finish.
Please help!I managed your email address
hardly(stackoverflow->google->github).I need the solution badly.
Thanks in advance.

Regards
RiskyCoder

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

Reply via email to