获取短彩信会话列表 content://mms-sms/conversations

http://kevinlynx.iteye.com/blog/857633

http://topic.csdn.net/u/20100804/12/67607078-e17c-4afc-8228-9dcf9a366b03.html?seed=1998627157&r=76024741#r_76024741

Android中的短信并没有正式的content provider可用,在官方文档中没有提供定义。不过依然可以自己定义好URI,然后查询出短信内容。例如conetent://sms则是所有短信所在的path。

要将短信按会话分类,原先我是查询出所有短信后,然后再按照thread_id分类。系统自带的短信程序包含一个会话显示界面,每个条目包含:联系人、短信数量、第一条短信等内容。当我的程序处理的短信较多时,一次查询出所有的短信就变得很慢。(如果再加上为每个会话查询联系人信息,则会更慢)

看了系统短信的代码,发现它可以只查询出会话的信息,而不用查询出所有短信内容。因为部分代码没找到,一直不知道它是怎么做到的。看了telphony provider的代码后,才知晓一二。

实际上,短信数据库中(mmssms.db)并没有一个表存储会话信息的。 系统提供的content provider中,实际上是支持直接查询会话信息的。只不过,其实现方式,不是通过一个现成的表,而是通过SQL语句,从多个表里取数据完成的。关于这个实现方式,在 这个帖子中也有所提及。

实现方式就不深究了,毕竟我对SQL查询不太熟。放出直接的使用方法:


通过指定simple=true,则可以获取出一个大概的会话数据,包含以下列:
 


列名则为: threads表吧

参考: http://stackoverflow.com/questions/3012287/how-to-read-mms-data-in-android
其中:
  • _id is the ID of the message. Captain obvious to the rescue? Not really. This ID can be used to retrieve detailed information using either content://sms or content://mms.
  • body The content of the last SMS on this conversation. If it's an MMS, even if it has a text part, this will be null.
  • thread_id is the ID of the conversation
  • date no explanation needed.
  • "ct_t"  信息类型,如果是 "application/vnd.wap.multipart.related" 表示它是彩信

    Note: if you query content://mms-sms/conversations it will return a list of different conversations whose _id is the last SMS or MMS in each conversation. If you query content://mms-sms/conversations/xxx it will return each SMS and/or MMS on the conversation whose ID is xxx.


    1、message_count为该会话的消息数量;
    2、recipient_ids为联系人ID,这个ID不是联系人表中的_id,而是指向表  canonical_addresses 里的id,canonical_addresses这个表同样位于mmssms.db,它映射了recipient_ids到一个电话号码,也就是说,最终获取联系人信息,还是得通过电话号码; 
    3、snippet为最后收到/发送的短信;

    每个数据的类型嘛,大致为:


  • 你可能感兴趣的:(Date,String,query,each,sms,电话)