2012-09-19 86 views
6

我正在開發Android應用程序。我從以下uri中獲取了recipient_id。從「canonical_addresses」表獲取地址

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"地址。我在網上搜索了很多。請幫我找個解決方案的朋友。

回答

13

規範表有兩列,_idaddress。當您收到收件人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); 
+0

@ Vikki..thanks很多 – sarath

+0

這SOOO幫助很大 – toobsco42

+0

哎@Vikki,如果你想從URI「的內容得到的thread_id什麼:// MMS短信/通話?簡單=真」。你會怎麼做? – toobsco42

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