Skip to content Skip to sidebar Skip to footer

Finding Account Nature Of A Contact Group?

I am developing an application in which it is required to find the nature of a contact group means whether it is google group , phone group or sim group. How to find it.Please sugg

Solution 1:

The code below prints the contact name and type. I have not optimized it and it will print multiple records but I think you will know what to do.

package com.example.android.contactmanager;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.RawContacts;
import android.util.Log;

public final classContactManagerextendsActivity{

/**
 * Called when the activity is first created. Responsible for initializing the UI.
 */@OverridepublicvoidonCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    printContactList();
}

/**
 * Print contact data in logcat.
 * SIM : Account_Type = com.anddroid.contacts.sim
 * Phone : Depends on the manufacturer e.g For HTC : Account_Type = com.htc.android.pcsc
 * Google : Account_Type = com.google
 */privatevoidprintContactList() {
    Cursor cursor = getContacts();
    cursor.moveToFirst();
    while (cursor.isAfterLast() == false) {
        Log.d("Display_Name", cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)));
        Log.d("Account_Type", cursor.getString(cursor.getColumnIndex(RawContacts.ACCOUNT_TYPE)));
        cursor.moveToNext();

    }
}

/**
 * Obtains the contact list for the currently selected account.
 *
 * @return A cursor for for accessing the contact list.
 */privateCursorgetContacts()
{
    // Run queryUri uri = ContactsContract.Data.CONTENT_URI;
    String[] projection = newString[] {
            ContactsContract.Contacts._ID,
            ContactsContract.Contacts.DISPLAY_NAME,
            RawContacts.ACCOUNT_TYPE
    };
    String[] selectionArgs = null;
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

    returnmanagedQuery(uri, projection, null, selectionArgs, sortOrder);
}
}

Solution 2:

I have same problem which you have mentioned i solved it like this way

ArrayList<GroupNameDetails> stateList = new ArrayList<GroupNameDetails>();
      finalString[] GROUP_PROJECTION = newString[] 
                {
                    ContactsContract.Groups._ID, ContactsContract.Groups.TITLE,   ContactsContract.Groups.ACCOUNT_TYPE//this line will do the trick
                };
            Cursor cursor = getContentResolver().query(ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null,
                    null, ContactsContract.Groups.TITLE);
            while (cursor.moveToNext()) {
                String accountname=cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.ACCOUNT_TYPE));
                Toast.makeText(getBaseContext(), accountname, Toast.LENGTH_LONG).show();// and it will display group typeString id = cursor.getString(cursor.getColumnIndex(ContactsContract.Groups._ID));
                Log.v("Test", id);
                //ContactsContract.Groups.ACCOUNT_NAMEString gTitle = (cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.TITLE)));
                if(favGroupName.contains(gTitle)==false)
                {
                favGroupId.add(id);
                favGroupName.add(gTitle);

                GroupNameDetails _states = new GroupNameDetails(Long.parseLong(id),gTitle, false);
                stateList.add(_states);
                }
                Log.v("Test", gTitle);
                if (gTitle.contains("Favorite_")) {
                    gTitle = "Favorites";

                }

            }

Post a Comment for "Finding Account Nature Of A Contact Group?"