Android - Android Read recent SMS messages from command line

This is really ugly, but you can read them from the command line by using sqlite3 to view the database entries. You'll probably need to dig up a binary for this unless you have a custom ROM installed. There are some instructions for installing said binary in this Stack Overflow question, and SuperOneClick comes packaged with it (a copy of the binary itself can be found here).

If you do need to install the binary, use mount (with no parameters) to determine where your /system partition is physically located (mine is /dev/block/mtdblock3, for example). Then follow the instructions in the first link above, and start by remounting it in read/write mode with the command:

mount -o rw,remount /your/system/partition /system

Once you have sqlite3 you'll want to open an adb shell, switch to root with su, and then do the following:

# cd /data/data
cd /data/data
# cd com.android.providers.telephony/databases ***
cd com.android.providers.telephony/databases
# sqlite3 mmssms.db
sqlite3 mmssms.db
SQLite version 3.7.2
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> SELECT * FROM sms WHERE read=0;

This will pull up all of the rows from the table for all of the unread messages. The columns in the table are defined thusly (so you can trim the SELECT):

CREATE TABLE sms (_id INTEGER PRIMARY KEY,thread_id INTEGER,address TEXT,
  person INTEGER,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);

***Note for the marked line: this may be slightly different depending on your device and version of Android which is why I have included this cd command separately. I think it used to be com.android.providers/telephony/databases on older devices but I don't quite remember. Use ls to look around for the proper pathing here.


Alternatively, you could try copying the .db file onto your SD card (or pulling it with adb pull) and then reading it on your computer with sqlite.


Thanks to the beautiful hint above from eldarerathis, I just do

DB=/data/data/com.android.providers.telephony/databases/mmssms.db
echo 'select address,body from sms;' | ./sqlite3 -csv $DB 

to read my SMSes from my root prompt.

Since I didn't have sqlite3, I first had to download it with

curl http://dl.dropbox.com/u/16958605/sqlite3
chmod a+x sqlite3

Or see SQLite3 installer on Google Play (if you don't trust the dropbox source).