Davita
Davita

Reputation: 9144

Android SMS _id

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 :)

Upvotes: 0

Views: 2254

Answers (3)

Harneet Kaur
Harneet Kaur

Reputation: 4497

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

Upvotes: 3

Alex Lockwood
Alex Lockwood

Reputation: 83311

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.

Upvotes: 5

Fernando Camargo
Fernando Camargo

Reputation: 3110

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

Upvotes: 2

Related Questions