android apk操作簡訊資料時,不能使用sqlhelper直接操作,需要使用協議,協議使用uri轉義
content://sms/inbox 收件箱
content://sms/sent 已傳送
content://sms/draft 草稿
content://sms/outbox 發件中
content://sms/failed 失敗
content://sms/queued 待傳送
資料庫中sms相關的字段如下:
_id primary key integer 與words表內的source_id關聯
thread_id 會話id,乙個聯絡人的會話乙個id,與threads表內的_id關聯 integer
address 對方號碼 text
person 聯絡人id integer
date 發件日期 integer
protocol 通訊協議,判斷是簡訊還是彩信 integer 0:sms_rpoto, 1:mms_proto
read 是否閱讀 integer default 0 0:未讀, 1:已讀
status 狀態 integer default-1 -1:接收,
0:complete,
64: pending,
128: failed
type
簡訊型別 integer 1:inbox
2:sent
3:draft56
4:outbox
5:failed
6:queued
body 內容
service_center 服務中心號碼
subject 主題
reply_path_present
locked
error_code
seen
具體使用方法:
cursor cursor = mcontentresolver.query(uri.parse("content://sms"),
string projection, string selection, string selectionargs,string sortorder);
if(cursor!=null)
if(cursor.movetofirst())
query轉義sql語句時將query函式中的引數轉義為
select projection from sms where selection = selectionargs order by sortorder
由於android2.2 messaging中儲存草稿簡訊時不會將address存入sms表中,而以thread_id為索引,將草稿簡訊的address存入canonical_addresses表中而導致僅根據協議無法查詢到draft msgs address(這種設計缺陷是因為android為了使ui更加效率而使draft msgs不同於其他型別的msgs儲存方式所導致的),那麼根據這樣的轉義方式我們可以擴充套件一下這種select語句使他可以查詢到sms表以外的東西:
cursor draftcursor = mresolver.query(uri.parse("content://sms"),
new string ,
null, null, null);
有點耍滑頭,是吧,用到了sql語句中注釋符號「--」
這樣我們就將這個語句轉化為了:
select canonical_addresses.address from sms,threads,canonical_addresses where sms.thread_id=threads._id and threads.recipient_ids=canonical_addresses._id and sms._id = 'target_message_id' -- from sms
在sql語句解析的時候,--from sms是不予解析的,所以就成功執行了前面的聯合查詢操作而得到了我們想要的canonical_addresses表中的address資料。
簡單的android sms database操作就講這些,權當拋磚引玉,畢竟群眾的力量是無限的嘛
以後我將詳細講解下android mmssms.db資料庫中關於sms的內容以及部分簡訊操作的編碼技巧
android簡訊模組資料庫
路徑 data data com.android.providers.telephony databases mmssms.db sms的uri content sms 發件箱 content sms outbox 收件箱 content sms inbox 草稿箱 content sms draf...
Android檢視簡訊資料庫
一 首先,得找一部root過的手機。1 進入命令視窗。ctrl r cmd 確認 2 adb pull data data com.android.providers.telephony databases mmssms.db mmssms.db 在命令視窗中輸入這條指令。3 如果報沒有許可權的錯誤...
資料庫獲取 Android 簡訊
讀取簡訊需要的許可權 讀取資料庫簡訊方法 public static list getsmscode null,null,date desc 第二種,通過查詢條件,例如 date lasttime,過濾資料 uri.parse content sms new string,date new stri...