`

短信解析问题

 
阅读更多
近段时间做短信应用的相关开发,从最初的基本功能完成,到现在的操作性流畅,一步步优化,使运行速度变快、操作方便。从这一步步的调试过程中学习了不少知识,印象最为深刻的就是关于Uri的选择。 查询彩信和短信数据中每一个号码最新的一条信息:
Uri uri = Uri.parse(“content://mms-sms/conversations?simple=true”);
Cursor cursor = cr.query(uri, null, null, null, “date DESC”);
while (cursor.moveToNext()) {
cursor.getString(cursor.getColumnIndex(“_id”));//thread_id cursor.getLong(cursor.getColumnIndex(“date”));//发送或接收时间 cursor.getInt(cursor.getColumnIndex(“message_count”));//当前对话的所以信息总数
cursor.getString(cursor.getColumnIndex(“recipient_ids”));//canonical_address表的_id
cursor.getInt(cursor.getColumnIndex(“read”));//是否已读,0未读,1已读 cursor.getInt(cursor.getColumnIndex(“snippet_cs”));//标识此条数据是彩信还是短信,为空或是值为106为彩信,其它为短信 cursor.getString(cursor.getColumnIndex(“snippet”));//短信body,或是彩信主题 } cursor.close();
如图 通过thread_id查询与某联系人的所有聊天记录:
Uri uri = Uri.parse(“content://mms-sms/conversations/”+threadID); android 2.x的版本,联系人姓名、联系人电话号码 ,以及photo都分别存在不同的表中,第一次获取这些信息的时候,费了相当大的功夫,是一个表一个表的去匹配查询,不仅工作量大,而且速度极慢,后来才发现,系统提供了一个Uri可以一次把所有相关信息查询出来: android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_URI; 关于优化,最重要的就是查询出来的优化,只要查询速度快了,每个activity打开的速度自然也就快了,希望所有的童鞋们以后不要像我一样走弯路,费时费力,效率又低,找到合适的Uri,应用程序的效率才会高。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics