Search code examples
androidsqliteandroid-contentproviderandroid-cursor

How to fetch the contact details from recepient_ids in threads table


This is the 'threads' table instance

_id| recipient_ids| snippet
1  |   1          |Hi this is hello world
2  |   2          |Multiple send
3  | 1 3 4        |Send

The values corresponding to the recepient_ids are placed in 'canonical_addresses' table

_id|  address
1  |9879565655
2  |1111111111
3  |5465321348
4  |8965321354

Now i have to fetch the 'canonical_addresses.address' for each 'threads.recipient_ids' present in threads table (At times recipient_ids can be more than one) ?

Note: I'm using content://mms-sms/conversation to fetch details from threads table.


Solution

  • I couldnt find a direct solution towards it.

    Indeed, in order to get the recipient details query Content://sms/ with the thread id.

    select distinct address from the cursor.

    We will be able to get the recipient details.

    For more efficient ways pls respond to it.

    The snippet is as follows

    Uri THREAD_ID_CONTENT_URI = Uri.parse("content://sms/");
    
    Cursor cur = getContentResolver().query(uribuilder.build(), new String[]{"address"},"thread_id=#) group by (address", null,null);
    

    Thank u