获取短彩信会话列表 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查询不太熟。放出直接的使用方法:
	public static final Uri MMSSMS_FULL_CONVERSATION_URI = Uri.parse("content://mms-sms/conversations");
	public static final Uri CONVERSATION_URI = MMSSMS_FULL_CONVERSATION_URI.buildUpon().
		appendQueryParameter("simple", "true").build();


通过指定simple=true,则可以获取出一个大概的会话数据,包含以下列:
 
    private static final int ID             = 0;
    private static final int DATE           = 1;
    private static final int MESSAGE_COUNT  = 2;
    private static final int RECIPIENT_IDS  = 3;
    private static final int SNIPPET        = 4;
    private static final int SNIPPET_CS     = 5;
    private static final int READ           = 6;
    private static final int TYPE           = 7;
    private static final int ERROR          = 8;
    private static final int HAS_ATTACHMENT = 9;


列名则为: threads表吧
    private static final String[] ALL_THREADS_PROJECTION = {
        "_id", "date", "message_count", "recipient_ids",
        "snippet", "snippet_cs", "read", "error", "has_attachment"
    };
  • _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为最后收到/发送的短信;

    每个数据的类型嘛,大致为:
			long id = cursor.getLong(ID);
			long date = cursor.getLong(DATE);
			long msgCount = cursor.getLong(MESSAGE_COUNT);
			String recipIDs = cursor.getString(RECIPIENT_IDS);
			String snippet = cursor.getString(SNIPPET);
			long snippetCS = cursor.getLong(SNIPPET_CS);
			long read = cursor.getLong(READ);
			long type = cursor.getLong(TYPE);
			long error = cursor.getLong(ERROR);
			long hasAttach = cursor.getLong(HAS_ATTACHMENT);


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值