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

com.android.providers.telephony.MmsSmsDatabaseHelper的更多相关文章

  1. Android 使用Telephony API

    Android 使用Telephony API public class TelephonyDemo extends Activity { TextView textOut; TelephonyMan ...

  2. 真机无法接收到android.provider.Telephony.SMS_RECEIVED的问题

    小米2S有一个设定会导致,App无法接收到android.provider.Telephony.SMS_RECEIVED广播. 解决方案 关闭系统短信优先设置 短信-设置-高级设置-系统短信优先   ...

  3. import android.provider.Telephony cannot be resolved

    android.provider.Telephony is hidden. http://androidxref.com/4.0.3_r1/xref/frameworks/base/core/java ...

  4. Android -- com.android.providers.media,external.db

    external.db android是管理多媒体文件(音频.视频.图片)的信息是在/data/data/com.android.providers.media下的数据库文件external.db. ...

  5. java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/20 from pid=711, uid=10074 requires android.permission.READ_

    java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider ur ...

  6. 接收新信息,在会话中看不到(thread表数据插入/更新失败)

    分析原因:收到短信,sms表插入信息,触发器会自动更新thread表,更新失败导致一直有一条未读信息数量显示,但在会话列表中却看不到. (偶现,低概率. 解决方法:接收新信息插入后,立即查询threa ...

  7. android 管理手机短信

    为了看代码方便,一边在网上google资料,一边看Android java 源代码. 偶然发现了一个类MmsSmsDatabaseHelper.java,原来android将所有的短信信息都存入了mm ...

  8. (转)[Android实例] 关于使用ContentObserver监听不到删除短信会话的解决方案

    最近做通讯录的项目,需要实时监听短信的删除,就用到了观察者ContentObserver,怪异的事情就此发生,当我删除一条短信的时候,可以监听到,但是,当我删除整条短信的时候,就无法监听到,查了很多资 ...

  9. android 中管理短信

    为了看代码方便,一边在网上google资料,一边看Android java 源代码. 偶然发现了一个类MmsSmsDatabaseHelper.java,原来android将所有的短信信息都存入了mm ...

随机推荐

  1. C#中的集合(HashTable与Array类)【转】

    一.Array类 1.Array类的属性 序号 属性 & 描述 1 IsFixedSize 获取一个值,该值指示数组是否带有固定大小. 2 IsReadOnly 获取一个值,该值指示数组是否只 ...

  2. 【中文分词系列】 4. 基于双向LSTM的seq2seq字标注

    http://spaces.ac.cn/archives/3924/ 关于字标注法 上一篇文章谈到了分词的字标注法.要注意字标注法是很有潜力的,要不然它也不会在公开测试中取得最优的成绩了.在我看来,字 ...

  3. (文档)Shader.Find (在编译时,只包含那些使用中的shader或位置在"Resources"文件夹中shader)

    Shader.Find 查找 static function Find (name : string) : Shader Description描述 Finds a shader with the g ...

  4. How to center body on a page?

      [提问] I'm trying to center the body element on my HTML page. Basically, in the CSS I set the body e ...

  5. Redis实战总结-Redis的高可用性

    在之前的博客<Redis实战总结-配置.持久化.复制>给出了一种Redis主从复制机制,简单地实现了Redis高可用.然后,如果Master服务器宕机,会导致整个Redis瘫痪,这种方式的 ...

  6. JavaScript 将行结构数据转化为树形结构,可提供给常用的tree插件直接使用(高效转化方案)

    前台接收到的数据格式 var rows=[{ parent: 'root', id: 'DC', title: '集团' }, { parent: 'DC', id: '01', title: '上海 ...

  7. (纪录片)现代生活的秘密规则:算法 The Secret Rules of Modern Living: Algorithms

    简介: The Secret Rules of Modern Living: Algorithms (2015) 导演: David Briggs主演: Marcus du Sautoy类型: 纪录片 ...

  8. yii源码二 -- interfaces

    path:framework/base/interfaces.php overview:This file contains core interfaces for Yii framework. in ...

  9. C#.NET常见问题(FAQ)-public private protectd internal有什么区别

    首先要区分public和private,这两个修饰符是最常用的.Public就是对外公开的,private就是对外不公开的(类内部可以使用),比如下面我定义一个类的实例,自动补全代码中只有public ...

  10. Swift 2.x 升为 swift 3后语法不兼容问题适配

    [解决方法]设置 Build Settings —-> Use Legacy Swift Language Version —-> 改为YES