Android SMS _id

余生长醉 提交于 2019-12-25 02:21:25

问题


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


回答1:


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




回答2:


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.




回答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



来源:https://stackoverflow.com/questions/11075938/android-sms-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!