tags:

views:

83

answers:

3

I'm trying to reduce the number of queries I do to the Android's database. Basically I want to get any email or IM address that contains a user defined search term. Right now I'm doing two separate queries:

Email:

Cursor emails = cr.query( ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, ContactsContract.CommonDataKinds.Email.DATA + " LIKE ?", new String[] {searchTerm}, null);

IM:

Cursor cursor = cr.query( ContactsContract.Data.CONTENT_URI, null, ContactsContract.CommonDataKinds.Im.DATA + " LIKE ?", new String[] {searchTerm}, null);

Does anyone know of an easy way to combine both queries? The crux of the problem seems to be that the two content URI's are different.

Simon

A: 

It is possible if you are developing your own content provider. You simple need to add new URI and execute custom query when you processing it.

However it is impossible if you are using 3rd party content provider because SQLite database (or something else) is encapsulated for it's consumer.

cement
+1  A: 

You could try joining the tables using a MatrixCursor.

Here is an example.

aprock
A: 

I found out that if you do a query like this:

Cursor c = mApp.getContentResolver().query(ContactsContract.Data.CONTENT_URI,
    null,
    null,
    null,
    ContactsContract.Data.CONTACT_ID + " ASC");

You will get a very large table with all the data. Then you need to check the mimetype column to find out what type of data is contained in that row. From that you can extract all the emails and IMs for a given contact.

Simon MacDonald