MmsSmsDatabaseHelper 大致讲解

com.android.providers.telephony.MmsSmsDatabaseHelper

SmsProvider, MmsProvider, MmsSmsProvider利用MmsSmsDatabaseHelper来操作数据库。

1. MmsSmsDatabaseHelper继承了SQLiteOpenHelper。

public class MmsSmsDatabaseHelper extends SQLiteOpenHelper

它至少需要实现三个方法:构造方法、onCreate方法、onUpdate方法。

2. 实现私有构造方法。

private MmsSmsDatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);

    mContext = context;
}

3. 通过getInstance()方法获取MmsSmsDatabaseHelper的一个实例。

static synchronized MmsSmsDatabaseHelper getInstance(Context context) {
    if (sInstance == null) {
        sInstance = new MmsSmsDatabaseHelper(context);
    }
    return sInstance;
}

4. 在onCreate()方法中创建数据库表、触发器、索引。

@Override
public void onCreate(SQLiteDatabase db) {
    createMmsTables(db);
    createSmsTables(db);
    createCommonTables(db);
    createCommonTriggers(db);
    createMmsTriggers(db);
    createWordsTables(db);
    createIndices(db);
}

5. 实现了onUpgrade()方法。

public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion)

6. 在createCommonTables(db)方法中

(1)创建表threads表。

This table maps the subject and an ordered set of recipient IDs, separated by spaces, to a unique thread ID.  The IDs come from the canonical_addresses table.  This works because messages are considered to be part of the same thread if they have the same subject (or a null subject) and the same set of recipients.

db.execSQL("CREATE TABLE threads (" +
           Threads._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
           Threads.DATE + " INTEGER DEFAULT 0," +
           Threads.MESSAGE_COUNT + " INTEGER DEFAULT 0," +
           Threads.RECIPIENT_IDS + " TEXT," +
           Threads.SNIPPET + " TEXT," +
           Threads.SNIPPET_CHARSET + " INTEGER DEFAULT 0," +
           Threads.READ + " INTEGER DEFAULT 1," +
           Threads.TYPE + " INTEGER DEFAULT 0," +
           Threads.ERROR + " INTEGER DEFAULT 0," +
           Threads.HAS_ATTACHMENT + " INTEGER DEFAULT 0);");

(2)创建canonical_addresses表。

This table maps the first instance seen of any particular MMS/SMS address to an ID, which is then used as its canonical(标准的,权威的) representation.  If the same address or an equivalent address (as determined by our Sqlite PHONE_NUMBERS_EQUAL extension) is seen later, this same ID will be used. The _id is created with AUTOINCREMENT so it will never be reused again if a recipient is deleted.

db.execSQL("CREATE TABLE canonical_addresses (" +
           "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
           "address TEXT);");

(3)创建sms表。

字段status解析:a TP-Status value or -1 if it status hasn't been received。

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" +
           ");");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值