Android短信_id

时间:2012-06-18 00:50:22

标签: android sqlite sms android-contentprovider

我用谷歌搜索了几次但找不到我要找的东西。 Android为每条短信息分配一个id。我想知道这个id是否总是独一无二的?我可以依靠它来识别短信,还是应该自己分配?

谢谢:)

3 个答案:

答案 0 :(得分:4)

查看MmsSmsDatabaseHelper的源代码,并注意createSmsTables方法的实现:

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 */
}

分配给每个sms消息的_idPRIMARY KEY所以是的,它唯一地标识每个sms消息。

答案 1 :(得分:2)

由于它使用SQLite,即关系数据库,因此不可能有重复的标识符。

答案 2 :(得分:2)

SMS_ID对于每条消息都是唯一的。但是还有另一个名为Thread_ID的列,每个对话都很常见,即android手机中的非常对话已经给出了唯一的Thread_Id.But该特定线程中的每条消息都有一个唯一的SMS_ID