Android短信彩信开发手记(一):数据库相关

参考:

http://gnibre.iteye.com/blog/558031

http://www.cnblogs.com/qinglong1983/

http://jackyear.is-programmer.com/


短信 sms

文件 /data/data/com.android.providers.telephony/databases/mmssms.db
这个数据库有13张表,sms表存了短信信息。

短信收件箱对应的URI是content://sms/inbox

很简单吧,就是sms短信,然后inbox收件箱,类似,短信里面的URI分别是

content://sms/

content://sms/inbox

content://sms/sent

content://sms/draft

content://sms/outbox

content://sms/failed

content://sms/queued


android.provider.Telephony:

  1. /**
  2. *ThethreadIDofthemessage
  3. *<P>Type:INTEGER</P>
  4. */
  5. publicstaticfinalStringTHREAD_ID="thread_id";
  6. /**
  7. *Theaddressoftheotherparty
  8. *<P>Type:TEXT</P>
  9. */
  10. publicstaticfinalStringADDRESS="address";
  11. /**
  12. *ThepersonIDofthesender
  13. *<P>Type:INTEGER(long)</P>
  14. */
  15. publicstaticfinalStringPERSON_ID="person";
  16. /**
  17. *Thedatethemessagewassent
  18. *<P>Type:INTEGER(long)</P>
  19. */
  20. publicstaticfinalStringDATE="date";
  21. /**
  22. *Theprotocolidentifiercode
  23. *<P>Type:INTEGER</P>
  24. */
  25. publicstaticfinalStringPROTOCOL="protocol";
  26. /**
  27. *Hasthemessagebeenread
  28. *<P>Type:INTEGER(boolean)</P>
  29. */
  30. publicstaticfinalStringREAD="read";
  31. /**
  32. *TheTP-Statusvalueforthemessage,or-1ifnostatushas
  33. *beenreceived
  34. */
  35. publicstaticfinalStringSTATUS="status";
  36. us举例:
  37. publicstaticfinalintSTATUS_NONE=-1;
  38. publicstaticfinalintSTATUS_COMPLETE=0;
  39. publicstaticfinalintSTATUS_PENDING=64;
  40. publicstaticfinalintSTATUS_FAILED=128;
  41. /**
  42. *Thetypeofthemessage
  43. *<P>Type:INTEGER</P>
  44. */
  45. publicstaticfinalStringTYPE="type";
  46. 举例
  47. publicstaticfinalintMESSAGE_TYPE_ALL=0;
  48. publicstaticfinalintMESSAGE_TYPE_INBOX=1;
  49. publicstaticfinalintMESSAGE_TYPE_SENT=2;
  50. publicstaticfinalintMESSAGE_TYPE_DRAFT=3;
  51. publicstaticfinalintMESSAGE_TYPE_OUTBOX=4;
  52. publicstaticfinalintMESSAGE_TYPE_FAILED=5;//forfailedoutgoingmessages
  53. publicstaticfinalintMESSAGE_TYPE_QUEUED=6;//formessagestosendlater
  54. /**
  55. *Whetherthe<code>TP-Reply-Path</code>bitwassetonthismessage
  56. *<P>Type:BOOLEAN</P>
  57. */
  58. publicstaticfinalStringREPLY_PATH_PRESENT="reply_path_present";
  59. /**
  60. *Thesubjectofthemessage,ifpresent
  61. *<P>Type:TEXT</P>
  62. */
  63. publicstaticfinalStringSUBJECT="subject";
  64. /**
  65. *Thebodyofthemessage
  66. *<P>Type:TEXT</P>
  67. */
  68. publicstaticfinalStringBODY="body";
  69. /**
  70. *Theservicecenter(SC)throughwhichtosendthemessage,ifpresent
  71. *<P>Type:TEXT</P>
  72. */
  73. publicstaticfinalStringSERVICE_CENTER="service_center";
  74. /**
  75. *Hasthemessagebeenlocked?
  76. *<P>Type:INTEGER(boolean)</P>
  77. */
  78. publicstaticfinalStringLOCKED="locked";
  79. **
  80. *Theidofthesenderoftheconversation,ifpresent
  81. *<P>Type:INTEGER(referencetoitemincontent://contacts/people)</P>
  82. */
  83. publicstaticfinalStringPERSON="person";
/** * The thread ID of the message * <P>Type: INTEGER</P> */ public static final String THREAD_ID = "thread_id"; /** * The address of the other party * <P>Type: TEXT</P> */ public static final String ADDRESS = "address"; /** * The person ID of the sender * <P>Type: INTEGER (long)</P> */ public static final String PERSON_ID = "person"; /** * The date the message was sent * <P>Type: INTEGER (long)</P> */ public static final String DATE = "date"; /** * The protocol identifier code * <P>Type: INTEGER</P> */ public static final String PROTOCOL = "protocol"; /** * Has the message been read * <P>Type: INTEGER (boolean)</P> */ public static final String READ = "read"; /** * The TP-Status value for the message, or -1 if no status has * been received */ public static final String STATUS = "status"; us 举例: public static final int STATUS_NONE = -1; public static final int STATUS_COMPLETE = 0; public static final int STATUS_PENDING = 64; public static final int STATUS_FAILED = 128; /** * The type of the message * <P>Type: INTEGER</P> */ public static final String TYPE = "type"; 举例 public static final int MESSAGE_TYPE_ALL = 0; public static final int MESSAGE_TYPE_INBOX = 1; public static final int MESSAGE_TYPE_SENT = 2; public static final int MESSAGE_TYPE_DRAFT = 3; public static final int MESSAGE_TYPE_OUTBOX = 4; public static final int MESSAGE_TYPE_FAILED = 5; // for failed outgoing messages public static final int MESSAGE_TYPE_QUEUED = 6; // for messages to send later /** * Whether the <code>TP-Reply-Path</code> bit was set on this message * <P>Type: BOOLEAN</P> */ public static final String REPLY_PATH_PRESENT = "reply_path_present"; /** * The subject of the message, if present * <P>Type: TEXT</P> */ public static final String SUBJECT = "subject"; /** * The body of the message * <P>Type: TEXT</P> */ public static final String BODY = "body"; /** * The service center (SC) through which to send the message, if present * <P>Type: TEXT</P> */ public static final String SERVICE_CENTER = "service_center"; /** * Has the message been locked? * <P>Type: INTEGER (boolean)</P> */ public static final String LOCKED = "locked"; ** * The id of the sender of the conversation, if present * <P>Type: INTEGER (reference to item in content://contacts/people)</P> */ public static final String PERSON = "person"; _id 一个自增字段,从1开始
thread_id 序号,同一发信人的id相同
address 发件人手机号码
person 联系人列表里的序号,陌生人为null (不稳定无法获取联系人ID)
date 发件日期
protocol 协议,分为: 0 SMS_RPOTO, 1 MMS_PROTO
read 是否阅读 0未读, 1已读
status 状态 -1接收,0 complete, 64 pending, 128 failed
type
ALL = 0;
INBOX = 1;
SENT = 2;
DRAFT = 3;
OUTBOX = 4;
FAILED = 5;
QUEUED = 6;
body 短信内容
service_center 短信服务中心号码编号
subject 短信的主题
reply_path_present TP-Reply-Path

locked



Url中content://sms 替换成content://sms/ 也成功,但是其它url时程序报错,比如content://sms/inbox

看了一下android的源代码,sms支持的协议有:


sURLMatcher.addURI("sms", null, SMS_ALL);
sURLMatcher.addURI("sms", "#", SMS_ALL_ID);
sURLMatcher.addURI("sms", "inbox", SMS_INBOX);
sURLMatcher.addURI("sms", "inbox/#", SMS_INBOX_ID);
sURLMatcher.addURI("sms", "sent", SMS_SENT);
sURLMatcher.addURI("sms", "sent/#", SMS_SENT_ID);
sURLMatcher.addURI("sms", "draft", SMS_DRAFT);
sURLMatcher.addURI("sms", "draft/#", SMS_DRAFT_ID);
sURLMatcher.addURI("sms", "outbox", SMS_OUTBOX);
sURLMatcher.addURI("sms", "outbox/#", SMS_OUTBOX_ID);
sURLMatcher.addURI("sms", "undelivered", SMS_UNDELIVERED);
sURLMatcher.addURI("sms", "failed", SMS_FAILED);
sURLMatcher.addURI("sms", "failed/#", SMS_FAILED_ID);
sURLMatcher.addURI("sms", "queued", SMS_QUEUED);
sURLMatcher.addURI("sms", "conversations", SMS_CONVERSATIONS);
sURLMatcher.addURI("sms", "conversations/*", SMS_CONVERSATIONS_ID);
sURLMatcher.addURI("sms", "raw", SMS_RAW_MESSAGE);
sURLMatcher.addURI("sms", "attachments", SMS_ATTACHMENT);
sURLMatcher.addURI("sms", "attachments/#", SMS_ATTACHMENT_ID);
sURLMatcher.addURI("sms", "threadID", SMS_NEW_THREAD_ID);
sURLMatcher.addURI("sms", "threadID/*", SMS_QUERY_THREAD_ID);
sURLMatcher.addURI("sms", "status/#", SMS_STATUS_ID);
sURLMatcher.addURI("sms", "sr_pending", SMS_STATUS_PENDING);
sURLMatcher.addURI("sms", "sim", SMS_ALL_SIM);
sURLMatcher.addURI("sms", "sim/#", SMS_SIM);


--------------------------------------------------------------------------------

其中,delete方法中支持的协议为:

SMS_ALL 根据参数中的条件删除sms表数据
SMS_ALL_ID 根据_id删除sms表数据
SMS_CONVERSATIONS_ID 根据thread_id删除sms表数据,可以带其它条件
SMS_RAW_MESSAGE 根据参数中的条件删除 raw表
SMS_STATUS_PENDING 根据参数中的条件删除 sr_pending表
SMS_SIM 从Sim卡上删除数据


试一下SMS_CONVERSATIONS_ID:"
在eclipse中的Emulator Control中,以13800给模拟器发送三条数据,然后以13900发送一条
this.getContentResolver().delete(Uri.parse("content://sms/conversations/3"), "_id=?", new String[]{"5"});
成功删除一条数据。

在数据库中每个发送者的thread_id虽然一样,但不是固定的,如果把一个发送者的全部数据删除掉,
然后换一个新号码发送短信时,thread_id是以数据库中最大的id+1赋值的。


--------------------------------------------------------------------------------

update支持的协议有很多:

SMS_RAW_MESSAGE
SMS_STATUS_PENDING
SMS_ALL
SMS_FAILED
SMS_QUEUED
SMS_INBOX
SMS_SENT
SMS_DRAFT
SMS_OUTBOX
SMS_CONVERSATIONS
SMS_ALL_ID
SMS_INBOX_ID
SMS_FAILED_ID
SMS_SENT_ID
SMS_DRAFT_ID
SMS_OUTBOX_ID
SMS_CONVERSATIONS_ID
SMS_STATUS_ID


以SMS_INBOX_ID测试一下:
ContentValues cv = new ContentValues();
cv.put("thread_id", "2");
cv.put("address", "00000");
cv.put("person", "11");
cv.put("date", "11111111");
this.getContentResolver().update(Uri.parse("content://sms/inbox/4"), cv, null, null);
太强了,连thread_id都可以修改。


--------------------------------------------------------------------------------

insert支持的协议:

SMS_ALL
SMS_INBOX
SMS_FAILED
SMS_QUEUED
SMS_SENT
SMS_DRAFT
SMS_OUTBOX
SMS_RAW_MESSAGE
SMS_STATUS_PENDING
SMS_ATTACHMENT
SMS_NEW_THREAD_ID


向sms表插入数据时,type是根据协议来自动设置,
如果传入的数据中没有设置date时,自动设置为当前系统时间;非SMS_INBOX协议时,read标志设置为1
SMS_INBOX协议时,系统会自动查询并设置PERSON
threadId为null或者0时,系统也会自动设置


一直为造不了"发送失败"的邮件而发愁,现在来做一个:
content://sms/failed


ContentValues cv = new ContentValues();
cv.put("_id", "99");
cv.put("thread_id", "0");
cv.put("address", "9999");
cv.put("person", "888");
cv.put("date", "9999");
cv.put("protocol", "0");
cv.put("read", "1");
cv.put("status", "-1");
//cv.put("type", "0");
cv.put("body", "@@@@@@@@@");

this.getContentResolver().insert(Uri.parse("content://sms/failed"), cv);
type被设置成了5,thread_id设置为1




彩信。

1、pdu表
mmssms.db库中的pdu表存储了彩信标题、彩信接收时间和彩信ID等信息,其中“_id”是主键,唯一标识了一个条彩信。
  1. /**
  2. *BasecolumnsfortablesthatcontainMMSs.
  3. */
  4. publicinterfaceBaseMmsColumnsextendsBaseColumns{
  5. publicstaticfinalintMESSAGE_BOX_ALL=0;
  6. publicstaticfinalintMESSAGE_BOX_INBOX=1;
  7. publicstaticfinalintMESSAGE_BOX_SENT=2;
  8. publicstaticfinalintMESSAGE_BOX_DRAFTS=3;
  9. publicstaticfinalintMESSAGE_BOX_OUTBOX=4;
  10. /**
  11. *Thedatethemessagewassent.
  12. *<P>Type:INTEGER(long)</P>
  13. */
  14. publicstaticfinalStringDATE="date";
  15. /**
  16. *Theboxwhichthemessagebelongto,forexample,MESSAGE_BOX_INBOX.
  17. *<P>Type:INTEGER</P>
  18. */
  19. publicstaticfinalStringMESSAGE_BOX="msg_box";
  20. /**
  21. *Hasthemessagebeenread.
  22. *<P>Type:INTEGER(boolean)</P>
  23. */
  24. publicstaticfinalStringREAD="read";
  25. /**
  26. *TheMessage-IDofthemessage.
  27. *<P>Type:TEXT</P>
  28. */
  29. publicstaticfinalStringMESSAGE_ID="m_id";
  30. /**
  31. *Thesubjectofthemessage,ifpresent.
  32. *<P>Type:TEXT</P>
  33. */
  34. publicstaticfinalStringSUBJECT="sub";
  35. /**
  36. *Thecharactersetofthesubject,ifpresent.
  37. *<P>Type:INTEGER</P>
  38. */
  39. publicstaticfinalStringSUBJECT_CHARSET="sub_cs";
  40. /**
  41. *TheContent-Typeofthemessage.
  42. *<P>Type:TEXT</P>
  43. */
  44. publicstaticfinalStringCONTENT_TYPE="ct_t";
  45. /**
  46. *TheContent-Locationofthemessage.
  47. *<P>Type:TEXT</P>
  48. */
  49. publicstaticfinalStringCONTENT_LOCATION="ct_l";
  50. /**
  51. *Theaddressofthesender.
  52. *<P>Type:TEXT</P>
  53. */
  54. publicstaticfinalStringFROM="from";
  55. /**
  56. *Theaddressoftherecipients.
  57. *<P>Type:TEXT</P>
  58. */
  59. publicstaticfinalStringTO="to";
  60. /**
  61. *Theaddressofthecc.recipients.
  62. *<P>Type:TEXT</P>
  63. */
  64. publicstaticfinalStringCC="cc";
  65. /**
  66. *Theaddressofthebcc.recipients.
  67. *<P>Type:TEXT</P>
  68. */
  69. publicstaticfinalStringBCC="bcc";
  70. /**
  71. *Theexpirytimeofthemessage.
  72. *<P>Type:INTEGER</P>
  73. */
  74. publicstaticfinalStringEXPIRY="exp";
  75. /**
  76. *Theclassofthemessage.
  77. *<P>Type:TEXT</P>
  78. */
  79. publicstaticfinalStringMESSAGE_CLASS="m_cls";
  80. /**
  81. *ThetypeofthemessagedefinedbyMMSspec.
  82. *<P>Type:INTEGER</P>
  83. */
  84. publicstaticfinalStringMESSAGE_TYPE="m_type";
  85. /**
  86. *Theversionofspecificationthatthismessageconform.
  87. *<P>Type:INTEGER</P>
  88. */
  89. publicstaticfinalStringMMS_VERSION="v";
  90. /**
  91. *Thesizeofthemessage.
  92. *<P>Type:INTEGER</P>
  93. */
  94. publicstaticfinalStringMESSAGE_SIZE="m_size";
  95. /**
  96. *Thepriorityofthemessage.
  97. *<P>Type:TEXT</P>
  98. */
  99. publicstaticfinalStringPRIORITY="pri";
  100. /**
  101. *Theread-reportofthemessage.
  102. *<P>Type:TEXT</P>
  103. */
  104. publicstaticfinalStringREAD_REPORT="rr";
  105. /**
  106. *Whetherthereportisallowed.
  107. *<P>Type:TEXT</P>
  108. */
  109. publicstaticfinalStringREPORT_ALLOWED="rpt_a";
  110. /**
  111. *Theresponse-statusofthemessage.
  112. *<P>Type:INTEGER</P>
  113. */
  114. publicstaticfinalStringRESPONSE_STATUS="resp_st";
  115. /**
  116. *Thestatusofthemessage.
  117. *<P>Type:INTEGER</P>
  118. */
  119. publicstaticfinalStringSTATUS="st";
  120. /**
  121. *Thetransaction-idofthemessage.
  122. *<P>Type:TEXT</P>
  123. */
  124. publicstaticfinalStringTRANSACTION_ID="tr_id";
  125. /**
  126. *Theretrieve-statusofthemessage.
  127. *<P>Type:INTEGER</P>
  128. */
  129. publicstaticfinalStringRETRIEVE_STATUS="retr_st";
  130. /**
  131. *Theretrieve-textofthemessage.
  132. *<P>Type:TEXT</P>
  133. */
  134. publicstaticfinalStringRETRIEVE_TEXT="retr_txt";
  135. /**
  136. *Thecharactersetoftheretrieve-text.
  137. *<P>Type:TEXT</P>
  138. */
  139. publicstaticfinalStringRETRIEVE_TEXT_CHARSET="retr_txt_cs";
  140. /**
  141. *Theread-statusofthemessage.
  142. *<P>Type:INTEGER</P>
  143. */
  144. publicstaticfinalStringREAD_STATUS="read_status";
  145. /**
  146. *Thecontent-classofthemessage.
  147. *<P>Type:INTEGER</P>
  148. */
  149. publicstaticfinalStringCONTENT_CLASS="ct_cls";
  150. /**
  151. *Thedelivery-reportofthemessage.
  152. *<P>Type:INTEGER</P>
  153. */
  154. publicstaticfinalStringDELIVERY_REPORT="d_rpt";
  155. /**
  156. *Thedelivery-time-tokenofthemessage.
  157. *<P>Type:INTEGER</P>
  158. */
  159. publicstaticfinalStringDELIVERY_TIME_TOKEN="d_tm_tok";
  160. /**
  161. *Thedelivery-timeofthemessage.
  162. *<P>Type:INTEGER</P>
  163. */
  164. publicstaticfinalStringDELIVERY_TIME="d_tm";
  165. /**
  166. *Theresponse-textofthemessage.
  167. *<P>Type:TEXT</P>
  168. */
  169. publicstaticfinalStringRESPONSE_TEXT="resp_txt";
  170. /**
  171. *Thesender-visibilityofthemessage.
  172. *<P>Type:TEXT</P>
  173. */
  174. publicstaticfinalStringSENDER_VISIBILITY="s_vis";
  175. /**
  176. *Thereply-chargingofthemessage.
  177. *<P>Type:INTEGER</P>
  178. */
  179. publicstaticfinalStringREPLY_CHARGING="r_chg";
  180. /**
  181. *Thereply-charging-deadline-tokenofthemessage.
  182. *<P>Type:INTEGER</P>
  183. */
  184. publicstaticfinalStringREPLY_CHARGING_DEADLINE_TOKEN="r_chg_dl_tok";
  185. /**
  186. *Thereply-charging-deadlineofthemessage.
  187. *<P>Type:INTEGER</P>
  188. */
  189. publicstaticfinalStringREPLY_CHARGING_DEADLINE="r_chg_dl";
  190. /**
  191. *Thereply-charging-idofthemessage.
  192. *<P>Type:TEXT</P>
  193. */
  194. publicstaticfinalStringREPLY_CHARGING_ID="r_chg_id";
  195. /**
  196. *Thereply-charging-sizeofthemessage.
  197. *<P>Type:INTEGER</P>
  198. */
  199. publicstaticfinalStringREPLY_CHARGING_SIZE="r_chg_sz";
  200. /**
  201. *Thepreviously-sent-byofthemessage.
  202. *<P>Type:TEXT</P>
  203. */
  204. publicstaticfinalStringPREVIOUSLY_SENT_BY="p_s_by";
  205. /**
  206. *Thepreviously-sent-dateofthemessage.
  207. *<P>Type:INTEGER</P>
  208. */
  209. publicstaticfinalStringPREVIOUSLY_SENT_DATE="p_s_d";
  210. /**
  211. *Thestoreofthemessage.
  212. *<P>Type:TEXT</P>
  213. */
  214. publicstaticfinalStringSTORE="store";
  215. /**
  216. *Themm-stateofthemessage.
  217. *<P>Type:INTEGER</P>
  218. */
  219. publicstaticfinalStringMM_STATE="mm_st";
  220. /**
  221. *Themm-flags-tokenofthemessage.
  222. *<P>Type:INTEGER</P>
  223. */
  224. publicstaticfinalStringMM_FLAGS_TOKEN="mm_flg_tok";
  225. /**
  226. *Themm-flagsofthemessage.
  227. *<P>Type:TEXT</P>
  228. */
  229. publicstaticfinalStringMM_FLAGS="mm_flg";
  230. /**
  231. *Thestore-statusofthemessage.
  232. *<P>Type:TEXT</P>
  233. */
  234. publicstaticfinalStringSTORE_STATUS="store_st";
  235. /**
  236. *Thestore-status-textofthemessage.
  237. *<P>Type:TEXT</P>
  238. */
  239. publicstaticfinalStringSTORE_STATUS_TEXT="store_st_txt";
  240. /**
  241. *Thestoredofthemessage.
  242. *<P>Type:TEXT</P>
  243. */
  244. publicstaticfinalStringSTORED="stored";
  245. /**
  246. *Thetotalsofthemessage.
  247. *<P>Type:TEXT</P>
  248. */
  249. publicstaticfinalStringTOTALS="totals";
  250. /**
  251. *Thembox-totalsofthemessage.
  252. *<P>Type:TEXT</P>
  253. */
  254. publicstaticfinalStringMBOX_TOTALS="mb_t";
  255. /**
  256. *Thembox-totals-tokenofthemessage.
  257. *<P>Type:INTEGER</P>
  258. */
  259. publicstaticfinalStringMBOX_TOTALS_TOKEN="mb_t_tok";
  260. /**
  261. *Thequotasofthemessage.
  262. *<P>Type:TEXT</P>
  263. */
  264. publicstaticfinalStringQUOTAS="qt";
  265. /**
  266. *Thembox-quotasofthemessage.
  267. *<P>Type:TEXT</P>
  268. */
  269. publicstaticfinalStringMBOX_QUOTAS="mb_qt";
  270. /**
  271. *Thembox-quotas-tokenofthemessage.
  272. *<P>Type:INTEGER</P>
  273. */
  274. publicstaticfinalStringMBOX_QUOTAS_TOKEN="mb_qt_tok";
  275. /**
  276. *Themessage-countofthemessage.
  277. *<P>Type:INTEGER</P>
  278. */
  279. publicstaticfinalStringMESSAGE_COUNT="m_cnt";
  280. /**
  281. *Thestartofthemessage.
  282. *<P>Type:INTEGER</P>
  283. */
  284. publicstaticfinalStringSTART="start";
  285. /**
  286. *Thedistribution-indicatorofthemessage.
  287. *<P>Type:TEXT</P>
  288. */
  289. publicstaticfinalStringDISTRIBUTION_INDICATOR="d_ind";
  290. /**
  291. *Theelement-descriptorofthemessage.
  292. *<P>Type:TEXT</P>
  293. */
  294. publicstaticfinalStringELEMENT_DESCRIPTOR="e_des";
  295. /**
  296. *Thelimitofthemessage.
  297. *<P>Type:INTEGER</P>
  298. */
  299. publicstaticfinalStringLIMIT="limit";
  300. /**
  301. *Therecommended-retrieval-modeofthemessage.
  302. *<P>Type:INTEGER</P>
  303. */
  304. publicstaticfinalStringRECOMMENDED_RETRIEVAL_MODE="r_r_mod";
  305. /**
  306. *Therecommended-retrieval-mode-textofthemessage.
  307. *<P>Type:TEXT</P>
  308. */
  309. publicstaticfinalStringRECOMMENDED_RETRIEVAL_MODE_TEXT="r_r_mod_txt";
  310. /**
  311. *Thestatus-textofthemessage.
  312. *<P>Type:TEXT</P>
  313. */
  314. publicstaticfinalStringSTATUS_TEXT="st_txt";
  315. /**
  316. *Theapplic-idofthemessage.
  317. *<P>Type:TEXT</P>
  318. */
  319. publicstaticfinalStringAPPLIC_ID="apl_id";
  320. /**
  321. *Thereply-applic-idofthemessage.
  322. *<P>Type:TEXT</P>
  323. */
  324. publicstaticfinalStringREPLY_APPLIC_ID="r_apl_id";
  325. /**
  326. *Theaux-applic-idofthemessage.
  327. *<P>Type:TEXT</P>
  328. */
  329. publicstaticfinalStringAUX_APPLIC_ID="aux_apl_id";
  330. /**
  331. *Thedrm-contentofthemessage.
  332. *<P>Type:TEXT</P>
  333. */
  334. publicstaticfinalStringDRM_CONTENT="drm_c";
  335. /**
  336. *Theadaptation-allowedofthemessage.
  337. *<P>Type:TEXT</P>
  338. */
  339. publicstaticfinalStringADAPTATION_ALLOWED="adp_a";
  340. /**
  341. *Thereplace-idofthemessage.
  342. *<P>Type:TEXT</P>
  343. */
  344. publicstaticfinalStringREPLACE_ID="repl_id";
  345. /**
  346. *Thecancel-idofthemessage.
  347. *<P>Type:TEXT</P>
  348. */
  349. publicstaticfinalStringCANCEL_ID="cl_id";
  350. /**
  351. *Thecancel-statusofthemessage.
  352. *<P>Type:INTEGER</P>
  353. */
  354. publicstaticfinalStringCANCEL_STATUS="cl_st";
  355. /**
  356. *ThethreadIDofthemessage
  357. *<P>Type:INTEGER</P>
  358. */
  359. publicstaticfinalStringTHREAD_ID="thread_id";
  360. /**
  361. *Hasthemessagebeenlocked?
  362. *<P>Type:INTEGER(boolean)</P>
  363. */
  364. publicstaticfinalStringLOCKED="locked";
  365. }
/** * Base columns for tables that contain MMSs. */ public interface BaseMmsColumns extends BaseColumns { public static final int MESSAGE_BOX_ALL = 0; public static final int MESSAGE_BOX_INBOX = 1; public static final int MESSAGE_BOX_SENT = 2; public static final int MESSAGE_BOX_DRAFTS = 3; public static final int MESSAGE_BOX_OUTBOX = 4; /** * The date the message was sent. * <P>Type: INTEGER (long)</P> */ public static final String DATE = "date"; /** * The box which the message belong to, for example, MESSAGE_BOX_INBOX. * <P>Type: INTEGER</P> */ public static final String MESSAGE_BOX = "msg_box"; /** * Has the message been read. * <P>Type: INTEGER (boolean)</P> */ public static final String READ = "read"; /** * The Message-ID of the message. * <P>Type: TEXT</P> */ public static final String MESSAGE_ID = "m_id"; /** * The subject of the message, if present. * <P>Type: TEXT</P> */ public static final String SUBJECT = "sub"; /** * The character set of the subject, if present. * <P>Type: INTEGER</P> */ public static final String SUBJECT_CHARSET = "sub_cs"; /** * The Content-Type of the message. * <P>Type: TEXT</P> */ public static final String CONTENT_TYPE = "ct_t"; /** * The Content-Location of the message. * <P>Type: TEXT</P> */ public static final String CONTENT_LOCATION = "ct_l"; /** * The address of the sender. * <P>Type: TEXT</P> */ public static final String FROM = "from"; /** * The address of the recipients. * <P>Type: TEXT</P> */ public static final String TO = "to"; /** * The address of the cc. recipients. * <P>Type: TEXT</P> */ public static final String CC = "cc"; /** * The address of the bcc. recipients. * <P>Type: TEXT</P> */ public static final String BCC = "bcc"; /** * The expiry time of the message. * <P>Type: INTEGER</P> */ public static final String EXPIRY = "exp"; /** * The class of the message. * <P>Type: TEXT</P> */ public static final String MESSAGE_CLASS = "m_cls"; /** * The type of the message defined by MMS spec. * <P>Type: INTEGER</P> */ public static final String MESSAGE_TYPE = "m_type"; /** * The version of specification that this message conform. * <P>Type: INTEGER</P> */ public static final String MMS_VERSION = "v"; /** * The size of the message. * <P>Type: INTEGER</P> */ public static final String MESSAGE_SIZE = "m_size"; /** * The priority of the message. * <P>Type: TEXT</P> */ public static final String PRIORITY = "pri"; /** * The read-report of the message. * <P>Type: TEXT</P> */ public static final String READ_REPORT = "rr"; /** * Whether the report is allowed. * <P>Type: TEXT</P> */ public static final String REPORT_ALLOWED = "rpt_a"; /** * The response-status of the message. * <P>Type: INTEGER</P> */ public static final String RESPONSE_STATUS = "resp_st"; /** * The status of the message. * <P>Type: INTEGER</P> */ public static final String STATUS = "st"; /** * The transaction-id of the message. * <P>Type: TEXT</P> */ public static final String TRANSACTION_ID = "tr_id"; /** * The retrieve-status of the message. * <P>Type: INTEGER</P> */ public static final String RETRIEVE_STATUS = "retr_st"; /** * The retrieve-text of the message. * <P>Type: TEXT</P> */ public static final String RETRIEVE_TEXT = "retr_txt"; /** * The character set of the retrieve-text. * <P>Type: TEXT</P> */ public static final String RETRIEVE_TEXT_CHARSET = "retr_txt_cs"; /** * The read-status of the message. * <P>Type: INTEGER</P> */ public static final String READ_STATUS = "read_status"; /** * The content-class of the message. * <P>Type: INTEGER</P> */ public static final String CONTENT_CLASS = "ct_cls"; /** * The delivery-report of the message. * <P>Type: INTEGER</P> */ public static final String DELIVERY_REPORT = "d_rpt"; /** * The delivery-time-token of the message. * <P>Type: INTEGER</P> */ public static final String DELIVERY_TIME_TOKEN = "d_tm_tok"; /** * The delivery-time of the message. * <P>Type: INTEGER</P> */ public static final String DELIVERY_TIME = "d_tm"; /** * The response-text of the message. * <P>Type: TEXT</P> */ public static final String RESPONSE_TEXT = "resp_txt"; /** * The sender-visibility of the message. * <P>Type: TEXT</P> */ public static final String SENDER_VISIBILITY = "s_vis"; /** * The reply-charging of the message. * <P>Type: INTEGER</P> */ public static final String REPLY_CHARGING = "r_chg"; /** * The reply-charging-deadline-token of the message. * <P>Type: INTEGER</P> */ public static final String REPLY_CHARGING_DEADLINE_TOKEN = "r_chg_dl_tok"; /** * The reply-charging-deadline of the message. * <P>Type: INTEGER</P> */ public static final String REPLY_CHARGING_DEADLINE = "r_chg_dl"; /** * The reply-charging-id of the message. * <P>Type: TEXT</P> */ public static final String REPLY_CHARGING_ID = "r_chg_id"; /** * The reply-charging-size of the message. * <P>Type: INTEGER</P> */ public static final String REPLY_CHARGING_SIZE = "r_chg_sz"; /** * The previously-sent-by of the message. * <P>Type: TEXT</P> */ public static final String PREVIOUSLY_SENT_BY = "p_s_by"; /** * The previously-sent-date of the message. * <P>Type: INTEGER</P> */ public static final String PREVIOUSLY_SENT_DATE = "p_s_d"; /** * The store of the message. * <P>Type: TEXT</P> */ public static final String STORE = "store"; /** * The mm-state of the message. * <P>Type: INTEGER</P> */ public static final String MM_STATE = "mm_st"; /** * The mm-flags-token of the message. * <P>Type: INTEGER</P> */ public static final String MM_FLAGS_TOKEN = "mm_flg_tok"; /** * The mm-flags of the message. * <P>Type: TEXT</P> */ public static final String MM_FLAGS = "mm_flg"; /** * The store-status of the message. * <P>Type: TEXT</P> */ public static final String STORE_STATUS = "store_st"; /** * The store-status-text of the message. * <P>Type: TEXT</P> */ public static final String STORE_STATUS_TEXT = "store_st_txt"; /** * The stored of the message. * <P>Type: TEXT</P> */ public static final String STORED = "stored"; /** * The totals of the message. * <P>Type: TEXT</P> */ public static final String TOTALS = "totals"; /** * The mbox-totals of the message. * <P>Type: TEXT</P> */ public static final String MBOX_TOTALS = "mb_t"; /** * The mbox-totals-token of the message. * <P>Type: INTEGER</P> */ public static final String MBOX_TOTALS_TOKEN = "mb_t_tok"; /** * The quotas of the message. * <P>Type: TEXT</P> */ public static final String QUOTAS = "qt"; /** * The mbox-quotas of the message. * <P>Type: TEXT</P> */ public static final String MBOX_QUOTAS = "mb_qt"; /** * The mbox-quotas-token of the message. * <P>Type: INTEGER</P> */ public static final String MBOX_QUOTAS_TOKEN = "mb_qt_tok"; /** * The message-count of the message. * <P>Type: INTEGER</P> */ public static final String MESSAGE_COUNT = "m_cnt"; /** * The start of the message. * <P>Type: INTEGER</P> */ public static final String START = "start"; /** * The distribution-indicator of the message. * <P>Type: TEXT</P> */ public static final String DISTRIBUTION_INDICATOR = "d_ind"; /** * The element-descriptor of the message. * <P>Type: TEXT</P> */ public static final String ELEMENT_DESCRIPTOR = "e_des"; /** * The limit of the message. * <P>Type: INTEGER</P> */ public static final String LIMIT = "limit"; /** * The recommended-retrieval-mode of the message. * <P>Type: INTEGER</P> */ public static final String RECOMMENDED_RETRIEVAL_MODE = "r_r_mod"; /** * The recommended-retrieval-mode-text of the message. * <P>Type: TEXT</P> */ public static final String RECOMMENDED_RETRIEVAL_MODE_TEXT = "r_r_mod_txt"; /** * The status-text of the message. * <P>Type: TEXT</P> */ public static final String STATUS_TEXT = "st_txt"; /** * The applic-id of the message. * <P>Type: TEXT</P> */ public static final String APPLIC_ID = "apl_id"; /** * The reply-applic-id of the message. * <P>Type: TEXT</P> */ public static final String REPLY_APPLIC_ID = "r_apl_id"; /** * The aux-applic-id of the message. * <P>Type: TEXT</P> */ public static final String AUX_APPLIC_ID = "aux_apl_id"; /** * The drm-content of the message. * <P>Type: TEXT</P> */ public static final String DRM_CONTENT = "drm_c"; /** * The adaptation-allowed of the message. * <P>Type: TEXT</P> */ public static final String ADAPTATION_ALLOWED = "adp_a"; /** * The replace-id of the message. * <P>Type: TEXT</P> */ public static final String REPLACE_ID = "repl_id"; /** * The cancel-id of the message. * <P>Type: TEXT</P> */ public static final String CANCEL_ID = "cl_id"; /** * The cancel-status of the message. * <P>Type: INTEGER</P> */ public static final String CANCEL_STATUS = "cl_st"; /** * The thread ID of the message * <P>Type: INTEGER</P> */ public static final String THREAD_ID = "thread_id"; /** * Has the message been locked? * <P>Type: INTEGER (boolean)</P> */ public static final String LOCKED = "locked"; }
2、part表
mmssms.db库中的part表存储了彩信内容(文本、音乐、图象)的文件名(即上面将的app_parts下面的文件名)、文件类型信息。
其中“mid”对应着pdu表中的“_id”,“ct”是文件类型,“_data”是存储路径。

3 。 彩信文件读取

彩信附件文件的地址存储在mmssms.db的part表的_data字段,形如“/data/data/com.android.providers.telephony/app_parts/PART_1262693697763”,但在应用中读取彩信附件时,这个字段基本没什么用,因为不能直接读取这个文件。读取同样要通过ContentProvider,URI为“content://mms/part”,该URI就是对应着part表。可以使用下列代码段来读取文件:
String selection = new String("mid='" + key + "'");//这个key就是pdu里面的_id。
Cursor cur = getContentResolver().query(Uri.parse("content://mms/part"), null, selection, null, null);

if (cur.moveToFirst())
do {
int _partID = cur.getInt(cur.getColumnIndex("_id"));
String partID = String.valueOf(_partID);
Uri partURI = Uri.parse("content://mms/part/" + partID);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = null;

try {
is = getContentResolver().openInputStream(partURI);
byte[] buffer = new byte[256];
int len = is.read(buffer);
while (len >= 0)
{
baos.write(buffer, 0, len);
len = is.read(buffer);
}
} catch (IOException e) {
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {

}
}
}
}
这里得到的baos,就是附件文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值