Fetch address from “canonical_addresses” table

允我心安 提交于 2019-12-19 02:07:10

问题


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.


回答1:


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);



回答2:


message = contentResolver.query(uri, null,null, null,SORT_ORDER);
            if(message != null){
                while (message.moveToNext()) {
                        String id = message.getString(message.getColumnIndex("_id"));
                        String thid = message.getString(message.getColumnIndex("thread_id"));
                        String phoneNumber = message.getString(message.getColumnIndex("address"));
                        String person = message.getString(message.getColumnIndex("person"));
                        //String present = message.getString(message.getColumnIndex("reply_path_present"));
                        //Log.v("sms "+thid,id);
                        //Log.v("sms "+present,present);
                        if(phoneNumber !=null ){
                                //if(phoneNumber.contains("-"))
                                    phoneNumber=phoneNumber.replaceAll("[-() ]", "");
                        }
                        else
                        {
                             Cursor c =contentResolver.query(Uri.parse("content://mms-sms/conversations?simple=true"), null, "_id = " + thid, null, null);
                             //getContentResolver().query(Uri.parse("content://mms-sms/canonical-addresses"), null, "_id = " + recipientId, null, null);
                             if(c.moveToNext())
                             {

                                 phoneNumber = c.getString(3);
                                 if(phoneNumber !=null ){
                                        //if(phoneNumber.contains("-"))
                                     Log.v(" id=>" +id+ " thid=>"+thid +" first = > " , c.getString(3));
                                }
                             }
                             c.close();
                             c =contentResolver.query(Uri.parse("content://mms-sms/canonical-addresses"), null, "_id = " + phoneNumber, null, null);
                             if(c.moveToNext())
                             {
                                 Log.v(thid +" second = > " , c.getString(1));
                                 phoneNumber = c.getString(1);
                                 phoneNumber=phoneNumber.replaceAll("[-() ]", "");
                             }
                             c.close();


来源:https://stackoverflow.com/questions/12492602/fetch-address-from-canonical-addresses-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!