0

I googled several times but couldn't find what I was looking for. Android assigns an id to each sms message. I wanted to know if this id is always unique? Can I rely on it to identify sms messages or should I assign my own?

Thanks :)

Charles
  • 50,943
  • 13
  • 104
  • 142
Davita
  • 8,928
  • 14
  • 67
  • 119

3 Answers3

5

Check out the source code for MmsSmsDatabaseHelper and note the implementation of the createSmsTables method:

private void createSmsTables(SQLiteDatabase db) {
    // N.B.: Whenever the columns here are changed, the columns in
    // {@ref MmsSmsProvider} must be changed to match.
    db.execSQL("CREATE TABLE sms (" +
               "_id INTEGER PRIMARY KEY," +
               "thread_id INTEGER," +
               "address TEXT," +
               "person INTEGER," +
               "date INTEGER," +
               "date_sent INTEGER DEFAULT 0," +
               "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" +
               ");");

    /* rest of implementation not shown */
}

The _id that is assigned to each sms message is a PRIMARY KEY so yes, it uniquely identifies each sms message.

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
3

SMS_ID is always unique for every message.But There is also another column named Thread_ID which is common for every conversation, i.e. very conversation in android phone has given unique Thread_Id.But each message within that particular thread has a unique SMS_ID

Harneet Kaur
  • 4,487
  • 1
  • 16
  • 16
2

Since it uses the SQLite, that is a relational database, it's impossible to have a duplicate identifier.

Fernando Camargo
  • 3,085
  • 4
  • 30
  • 49
  • @Fernando are the thread_id's also unique for each conversation? i.e. does all conversations have a unique id, even after i delete one? – harshit Oct 15 '12 at 06:28
  • Uhhh, SQLite doesn't enforce an unique key. Or other constraints. And it's not really a relational database. It's more like a text file with queries. – Davor Aug 22 '15 at 12:49