'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 1:[1]
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
Solution 2:[2]
you need to formulate the query as per the below:
String [] colAddress={"DISTINCT address"};
Cursor cur = getContentResolver().query(uriSMSURI, colAddress, null, null,null);
Solution 3:[3]
Use this uri for fetching
ContentResolver cr = context.getContentResolver();
Cursor pCur = cr.query(
Uri.parse("content://mms-sms/canonical-addresses"), new String[]{"address"},
"_id" + " = ?",
new String[]{your_thread_id}, null);
String contactAddress = null;
if (pCur != null) {
if (pCur.getCount() != 0) {
pCur.moveToNext();
contactAddress = pCur.getString(pCur.getColumnIndex("address"));
}
pCur.close();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | siva |
| Solution 2 | kay |
| Solution 3 | Context |
