7

我正在开发一个 Android 应用程序。我从以下 uri 中获取了收件人 ID。

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

现在我想从 canonical_addresses 获取地址" table using the recipient id. But I don't have any idea to query canonical_addresses table"。我在网上搜索了很多。请朋友帮我找解决办法。

4

2 回答 2

13

规范表有两列,_id并且address. 当您获得收件人 ID 时,您会在规范地址表中查找该 ID。对于多个收件人,ID 由空格分隔,因此您必须将结果拆分为

recipient_ids.split(" ")

并查找每个 id。

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

或者

getContentResolver().query(Uri.parse("content://mms-sms/canonical-address/" + recipientId), null, null, null, null);
于 2012-09-19T10:50:37.253 回答
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();
于 2013-04-10T05:53:03.743 回答