Android的短信保存在短信庫裡,但並提供類似Contacts的公開的Content Provider方便操作。這裡簡單的介紹下:android中的短信信息保存在/data/data/com.android.providers.telephony/databases目錄下的sqlite庫中。常用的表有:canonical_addresses, sms, threads。對短信的操作基本也就是對這些表的CRUD。下面先看下這些表的結構,也可以使用sql查看表中的內容
- d:\test>adb shell
- $ su
- su
- # cd /data/data/com.android.providers.telephony/databases
- cd /data/data/com.android.providers.telephony/databases
- # ls
- ls
- firewall.db mmssms.db-wal telephony.db-shm
- mmssms.db msmsms.db telephony.db-wal
- mmssms.db-shm telephony.db traffic.db
- # sqlite3 mmssms.db
- sqlite3 mmssms.db
- SQLite version 3.7.2
- Enter ".help" for instructions
- Enter SQL statements terminated with a ";"
- sqlite> .tables
- .tables
- addr pdu threads
- android_metadata pending_msgs words
- attachments rate words_content
- canonical_addresses raw words_segdir
- drm sms words_segments
- part sr_pending
- sqlite> .schema threads
- .schema threads
- CREATE TABLE threads (
- _id INTEGER PRIMARY KEY,
- date INTEGER DEFAULT 0,
- server_date INTEGER DEFAULT 0,
- message_count INTEGER DEFAULT 0,
- unread_count INTEGER DEFAULT 0,
- photo_id TEXT,
- recipient_addresses TEXT,
- recipient_names TEXT,
- is_sp TEXT,
- person_id TEXT,
- recipient_ids TEXT,
- snippet TEXT,s
- nippet_cs INTEGER DEFAULT 0,
- read INTEGER DEFAULT 1,
- type INTEGER DEFAULT 0,
- error INTEGER DEFAULT 0,
- has_attachment INTEGER DEFAULT 0,
- state INTEGER DEFAULT 0);
- sqlite> .schema sms
- .schema sms
- CREATE TABLE sms (
- _id INTEGER PRIMARY KEY,
- thread_id INTEGER,
- address TEXT,
- person INTEGER,
- date INTEGER,
- server_date INTEGER,
- protocol INTEGER,
- read INTEGER DEFAULT 0,
- status INTEGER DEFAULT -1,
- type INTEGER,
- reply_path_present INTEGER,
- subject TEXT,
- body TEXT,
- service_center TEXT,
- locked INTEGER DEFAULT 0,
- error_code INTEGER DEFAULT 0,
- seen INTEGER DEFAULT 0,
- timed INTEGER DEFAULT 0);
(這裡需要注意的是查看/data/data目錄下的文件需要有root權限)