Can I extend Androids Contacts database?
Asked Answered
B

1

7

I was wondering is it possible to extend the Android Contacts database?

From here - http://d.android.com/reference/android/provider/ContactsContract.html

It says:

ContactsContract defines an extensible database of contact-related information

Extensible would suggest to me that I can add in more data to the contacts application outside the normal values such as Name, number, email, work number, home number etc..

However the examples of this page - http://d.android.com/reference/android/provider/ContactsContract.RawContacts.html only show how to insert the standard values like name and not how to add a new field to a contact.

Furthermore a search on the web does not turn up much information on extending the contacts data.

So I was wondering is it even possible or does the extensible refer to some other part of the contacts?

For example I would like to add in an additional field for contacts that have special privileges within my app so when a user looks at the contacts he or she knows what users they can use my app with.

Is this possible?

Bridgework answered 19/1, 2011 at 18:29 Comment(0)
A
2

You can store custom data in the contacts database. However "when a user looks at the contacts he or she knows what users they can use my app with," may not be possible if you are thinking users will be able to see the custom data you inserted while using the built-in Android Contacts application. You would have to display the custom data in your own application.

The javadocs for the ContactsContract.Data class should provide an explanation, as well as the Contacts article.

To use this you'll need to get a raw contact id by querying the RawContacts.

Here some example code that might help you get started...

private void makePowerful(int rawContactId) {
    ContentValues values = new ContentValues();
    values.put(Privilege.RAW_CONTACT_ID, rawContactId);
    values.put(Privilege.MIMETYPE, Privilege.CONTENT_ITEM_TYPE);
    values.put(Privilege.PRIVILEGE_LEVEL, Privilege.TYPE_POWERFUL);
    Uri uri = getContentResolver().insert(Data.CONTENT_URI, values);
}

public static final class Privilege implements ContactsContract.DataColumnsWithJoins, ContactsContract.CommonDataKinds.CommonColumns {
    public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/my_app_privilege";
    public static final int TYPE_POWERFUL = 1;
    public static final int TYPE_WEAK = 2;
    public static final String PRIVILEGE_LEVEL = DATA1;

    private Privilege() { }
}
Adz answered 23/1, 2011 at 6:44 Comment(4)
Any idea where the Contacts article went to? The link is dead (:Burleson
I've updated the link, this one should help: developer.android.com/guide/topics/providers/…Adz
Thanks. It's to investigate a weird problem I have with the Contacts Database: wiert.me/2012/07/24/… (580 meg large, and automagically growing without any apps active).Burleson
Is it still the case? I see Whatsup added their icon so anyone can now see it and click it directly in the phone contacts list. I would like to perform a similar action.Pokelogan

© 2022 - 2024 — McMap. All rights reserved.