tags:

views:

12

answers:

1

Alright, I would like to make a class that can kinda make working with Content Providers a little easier, especially while working with contacts. I have something of a base layout, but its erroring out when I try to initiate cr. How would I be able to get something like this working?

Also, how does it look in general? From a design and efficiency perspective, as well as being an easy to use utility, would this be a good way to go about doing what I'd like to achieve?

public class ContactUtils {
    private Uri uri = ContactsContract.Contacts.CONTENT_URI;
    private ContentResolver cr = new ContentResolver(this);
    public String getDisplayName(int id) {
        String name = null;
        String[] projection = new String[] {ContactsContract.Contacts.DISPLAY_NAME};
        String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" + ("1") + "'";
        Cursor contact = cr.query(this.uri, projection, selection, null, null);
        while (contact.moveToFirst()) {
            name = contact.getString(contact.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
        }
        return name;
    }
}
A: 

The constructor of ContentResolver takes a Context a its single parameter. Your ContactUtils class does not extend Context and can therefore not be used as one.

Romain Guy
How would I go about doing something similar to what I have going on in my posted code then?
Chiggins