开发者

Help Creating a ContactsUtils class

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?

A开发者_C百科lso, 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;
    }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜