Search code examples
androidandroid-contentprovider

Fetch address from "canonical_addresses" table


I am working on an Android application. I fetched recipient_id from the following uri.

content://mms-sms/conversations?simple=true

Now I want to fetch the address from canonical_addresses" table using the recipient id. But I don't have any idea to query canonical_addresses table". I searched a lot in web. Please help me to find a solution friends.


Solution

  • Canonical table has two columns, _id and address. When you get recipient id you do a lookup for that id in the canonical addresses table. For multiple recipients the ids are separated by a space, so you'll have to split the result like

    recipient_ids.split(" ")

    and lookup each id.

    getContentResolver().query(Uri.parse("content://mms-sms/canonical-addresses"), null, "_id = " + recipientId, null, null);
    

    or

    getContentResolver().query(Uri.parse("content://mms-sms/canonical-address/" + recipientId), null, null, null, null);