Android SMS _id

2019-09-19 20:10发布

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

3条回答
Juvenile、少年°
2楼-- · 2019-09-19 20:48

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

查看更多
聊天终结者
3楼-- · 2019-09-19 21:00

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.

查看更多
Summer. ? 凉城
4楼-- · 2019-09-19 21:02

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

查看更多
登录 后发表回答