`
mars5337
  • 浏览: 86997 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

android 短信 彩信 数据库 转

阅读更多
短信 sms
文件 /data/data/com.android.providers.telephony/databases/mmssms.db
这个数据库有13张表,sms表存了短信信息。

sms表的uri是        
Java代码
public static final Uri CONTENT_URI = 
            Uri.parse("content://sms"); 

表项含义,我猜的
0 _id
1 thread_id   在短信界面里显示在第几组( 相同联系人的短信在同意行),英文名叫话题。
2 address   电话好吗
3 person   ? 存在电话簿里的名字 。 可能吧
4 date      日期
5 protocol  ?..
6 read      ?  1- 已读  0-未读 
7 status    ?
8 type      ? 2 我发送
9 reply_path_present   ?
10 subject
11 body      短信内容
12  service_center   ...

好没信息量。。。。

把源码补上。
在frameworks/base/core/java/android/provider/Telephony.java

Java代码
/**
  * The thread ID of the message
  * <P>Type: INTEGER</P>
  */ 
public static final String THREAD_ID = "thread_id"; 
 
/**
  * The address of the other party
  * <P>Type: TEXT</P>
  */ 
public static final String ADDRESS = "address"; 
 
/**
  * The person ID of the sender
  * <P>Type: INTEGER (long)</P>
  */ 
public static final String PERSON_ID = "person"; 
 
/**
  * The date the message was sent
  * <P>Type: INTEGER (long)</P>
  */ 
public static final String DATE = "date"; 
 
/**
  * The protocol identifier code
  * <P>Type: INTEGER</P>
  */ 
public static final String PROTOCOL = "protocol"; 
 
/**
  * Has the message been read
  * <P>Type: INTEGER (boolean)</P>
  */ 
public static final String READ = "read"; 
 
 
/**
  * The TP-Status value for the message, or -1 if no status has
  * been received
  */ 
public static final String STATUS = "status"; 
us 举例: 
public static final int STATUS_NONE = -1; 
public static final int STATUS_COMPLETE = 0; 
public static final int STATUS_PENDING = 64; 
public static final int STATUS_FAILED = 128; 
 
/**
  * The type of the message
  * <P>Type: INTEGER</P>
  */ 
public static final String TYPE = "type"; 
举例 
public static final int MESSAGE_TYPE_ALL    = 0; 
public static final int MESSAGE_TYPE_INBOX  = 1; 
public static final int MESSAGE_TYPE_SENT   = 2; 
public static final int MESSAGE_TYPE_DRAFT  = 3; 
public static final int MESSAGE_TYPE_OUTBOX = 4; 
public static final int MESSAGE_TYPE_FAILED = 5; // for failed outgoing messages 
public static final int MESSAGE_TYPE_QUEUED = 6; // for messages to send later 
 
 
/**
  * Whether the <code>TP-Reply-Path</code> bit was set on this message
  * <P>Type: BOOLEAN</P>
  */ 
public static final String REPLY_PATH_PRESENT = "reply_path_present"; 
 
/**
  * The subject of the message, if present
  * <P>Type: TEXT</P>
  */ 
public static final String SUBJECT = "subject"; 
 
 
/**
  * The body of the message
  * <P>Type: TEXT</P>
  */ 
public static final String BODY = "body"; 
 
 
/**
  * The service center (SC) through which to send the message, if present
  * <P>Type: TEXT</P>
  */ 
public static final String SERVICE_CENTER = "service_center"; 
 
 
 
/**
  * Has the message been locked?
  * <P>Type: INTEGER (boolean)</P>
  */ 
public static final String LOCKED = "locked"; 
 
** 
  * The id of the sender of the conversation, if present 
  * <P>Type: INTEGER (reference to item in content://contacts/people)</P> 
  */ 
public static final String PERSON = "person"; 




彩信。

1、pdu表
    mmssms.db库中的pdu表存储了彩信标题、彩信接收时间和彩信ID等信息,其中“_id”是主键,唯一标识了一个条彩信。

pdu 表源码
Java代码
/**
* Base columns for tables that contain MMSs.
*/ 
public interface BaseMmsColumns extends BaseColumns { 
 
    public static final int MESSAGE_BOX_ALL    = 0; 
    public static final int MESSAGE_BOX_INBOX  = 1; 
    public static final int MESSAGE_BOX_SENT   = 2; 
    public static final int MESSAGE_BOX_DRAFTS = 3; 
    public static final int MESSAGE_BOX_OUTBOX = 4; 
 
    /**
     * The date the message was sent.
     * <P>Type: INTEGER (long)</P>
     */ 
    public static final String DATE = "date"; 
 
    /**
     * The box which the message belong to, for example, MESSAGE_BOX_INBOX.
     * <P>Type: INTEGER</P>
     */ 
    public static final String MESSAGE_BOX = "msg_box"; 
 
    /**
     * Has the message been read.
     * <P>Type: INTEGER (boolean)</P>
     */ 
    public static final String READ = "read"; 
 
    /**
     * The Message-ID of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String MESSAGE_ID = "m_id"; 
 
    /**
     * The subject of the message, if present.
     * <P>Type: TEXT</P>
     */ 
    public static final String SUBJECT = "sub"; 
 
    /**
     * The character set of the subject, if present.
     * <P>Type: INTEGER</P>
     */ 
    public static final String SUBJECT_CHARSET = "sub_cs"; 
 
    /**
     * The Content-Type of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String CONTENT_TYPE = "ct_t"; 
 
    /**
     * The Content-Location of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String CONTENT_LOCATION = "ct_l"; 
 
    /**
     * The address of the sender.
     * <P>Type: TEXT</P>
     */ 
    public static final String FROM = "from"; 
 
    /**
     * The address of the recipients.
     * <P>Type: TEXT</P>
     */ 
    public static final String TO = "to"; 
 
    /**
     * The address of the cc. recipients.
     * <P>Type: TEXT</P>
     */ 
    public static final String CC = "cc"; 
 
    /**
     * The address of the bcc. recipients.
     * <P>Type: TEXT</P>
     */ 
    public static final String BCC = "bcc"; 
 
    /**
     * The expiry time of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String EXPIRY = "exp"; 
 
    /**
     * The class of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String MESSAGE_CLASS = "m_cls"; 
 
    /**
     * The type of the message defined by MMS spec.
     * <P>Type: INTEGER</P>
     */ 
    public static final String MESSAGE_TYPE = "m_type"; 
 
    /**
     * The version of specification that this message conform.
     * <P>Type: INTEGER</P>
     */ 
    public static final String MMS_VERSION = "v"; 
 
    /**
     * The size of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String MESSAGE_SIZE = "m_size"; 
 
    /**
     * The priority of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String PRIORITY = "pri"; 
 
    /**
     * The read-report of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String READ_REPORT = "rr"; 
 
    /**
     * Whether the report is allowed.
     * <P>Type: TEXT</P>
     */ 
    public static final String REPORT_ALLOWED = "rpt_a"; 
 
    /**
     * The response-status of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String RESPONSE_STATUS = "resp_st"; 
 
    /**
     * The status of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String STATUS = "st"; 
 
    /**
     * The transaction-id of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String TRANSACTION_ID = "tr_id"; 
 
    /**
     * The retrieve-status of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String RETRIEVE_STATUS = "retr_st"; 
 
    /**
     * The retrieve-text of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String RETRIEVE_TEXT = "retr_txt"; 
 
    /**
     * The character set of the retrieve-text.
     * <P>Type: TEXT</P>
     */ 
    public static final String RETRIEVE_TEXT_CHARSET = "retr_txt_cs"; 
 
    /**
     * The read-status of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String READ_STATUS = "read_status"; 
 
    /**
     * The content-class of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String CONTENT_CLASS = "ct_cls"; 
 
    /**
     * The delivery-report of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String DELIVERY_REPORT = "d_rpt"; 
 
    /**
     * The delivery-time-token of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String DELIVERY_TIME_TOKEN = "d_tm_tok"; 
 
    /**
     * The delivery-time of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String DELIVERY_TIME = "d_tm"; 
 
    /**
     * The response-text of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String RESPONSE_TEXT = "resp_txt"; 
 
    /**
     * The sender-visibility of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String SENDER_VISIBILITY = "s_vis"; 
 
    /**
     * The reply-charging of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String REPLY_CHARGING = "r_chg"; 
 
    /**
     * The reply-charging-deadline-token of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String REPLY_CHARGING_DEADLINE_TOKEN = "r_chg_dl_tok"; 
 
    /**
     * The reply-charging-deadline of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String REPLY_CHARGING_DEADLINE = "r_chg_dl"; 
 
    /**
     * The reply-charging-id of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String REPLY_CHARGING_ID = "r_chg_id"; 
 
    /**
     * The reply-charging-size of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String REPLY_CHARGING_SIZE = "r_chg_sz"; 
 
    /**
     * The previously-sent-by of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String PREVIOUSLY_SENT_BY = "p_s_by"; 
 
    /**
     * The previously-sent-date of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String PREVIOUSLY_SENT_DATE = "p_s_d"; 
 
    /**
     * The store of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String STORE = "store"; 
 
    /**
     * The mm-state of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String MM_STATE = "mm_st"; 
 
    /**
     * The mm-flags-token of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String MM_FLAGS_TOKEN = "mm_flg_tok"; 
 
    /**
     * The mm-flags of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String MM_FLAGS = "mm_flg"; 
 
    /**
     * The store-status of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String STORE_STATUS = "store_st"; 
 
    /**
     * The store-status-text of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String STORE_STATUS_TEXT = "store_st_txt"; 
 
    /**
     * The stored of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String STORED = "stored"; 
 
    /**
     * The totals of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String TOTALS = "totals"; 
 
    /**
     * The mbox-totals of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String MBOX_TOTALS = "mb_t"; 
 
    /**
     * The mbox-totals-token of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String MBOX_TOTALS_TOKEN = "mb_t_tok"; 
 
    /**
     * The quotas of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String QUOTAS = "qt"; 
 
    /**
     * The mbox-quotas of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String MBOX_QUOTAS = "mb_qt"; 
 
    /**
     * The mbox-quotas-token of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String MBOX_QUOTAS_TOKEN = "mb_qt_tok"; 
 
    /**
     * The message-count of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String MESSAGE_COUNT = "m_cnt"; 
 
    /**
     * The start of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String START = "start"; 
 
    /**
     * The distribution-indicator of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String DISTRIBUTION_INDICATOR = "d_ind"; 
 
    /**
     * The element-descriptor of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String ELEMENT_DESCRIPTOR = "e_des"; 
 
    /**
     * The limit of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String LIMIT = "limit"; 
 
    /**
     * The recommended-retrieval-mode of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String RECOMMENDED_RETRIEVAL_MODE = "r_r_mod"; 
 
    /**
     * The recommended-retrieval-mode-text of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String RECOMMENDED_RETRIEVAL_MODE_TEXT = "r_r_mod_txt"; 
 
    /**
     * The status-text of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String STATUS_TEXT = "st_txt"; 
 
    /**
     * The applic-id of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String APPLIC_ID = "apl_id"; 
 
    /**
     * The reply-applic-id of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String REPLY_APPLIC_ID = "r_apl_id"; 
 
    /**
     * The aux-applic-id of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String AUX_APPLIC_ID = "aux_apl_id"; 
 
    /**
     * The drm-content of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String DRM_CONTENT = "drm_c"; 
 
    /**
     * The adaptation-allowed of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String ADAPTATION_ALLOWED = "adp_a"; 
 
    /**
     * The replace-id of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String REPLACE_ID = "repl_id"; 
 
    /**
     * The cancel-id of the message.
     * <P>Type: TEXT</P>
     */ 
    public static final String CANCEL_ID = "cl_id"; 
 
    /**
     * The cancel-status of the message.
     * <P>Type: INTEGER</P>
     */ 
    public static final String CANCEL_STATUS = "cl_st"; 
 
    /**
     * The thread ID of the message
     * <P>Type: INTEGER</P>
     */ 
    public static final String THREAD_ID = "thread_id"; 
 
    /**
     * Has the message been locked?
     * <P>Type: INTEGER (boolean)</P>
     */ 
    public static final String LOCKED = "locked"; 



2、part表
    mmssms.db库中的part表存储了彩信内容(文本、音乐、图象)的文件名(即上面将的app_parts下面的文件名)、文件类型信息。
    其中“mid”对应着pdu表中的“_id”,“ct”是文件类型,“_data”是存储路径。

3 。 彩信文件读取

      彩信附件文件的地址存储在mmssms.db的part表的_data字段,形如“/data/data/com.android.providers.telephony/app_parts/PART_1262693697763”,但在应用中读取彩信附件时,这个字段基本没什么用,因为不能直接读取这个文件。读取同样要通过ContentProvider,URI为“content://mms/part”,该URI就是对应着part表。可以使用下列代码段来读取文件:
String selection = new String("mid='" + key + "'");//这个key就是pdu里面的_id。
Cursor cur = getContentResolver().query(Uri.parse("content://mms/part"), null, selection, null, null);

        if (cur.moveToFirst())
            do {
                    int _partID = cur.getInt(cur.getColumnIndex("_id"));
                    String partID = String.valueOf(_partID);
                    Uri partURI = Uri.parse("content://mms/part/" + partID);
                   
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    InputStream is = null;

                    try {
                        is = getContentResolver().openInputStream(partURI);
                        byte[] buffer = new byte[256];
                        int len = is.read(buffer);
                        while (len >= 0)
                        {
                            baos.write(buffer, 0, len);
                            len = is.read(buffer);
                        }
                    } catch (IOException e) {
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {

                            }
                        }
                    }
                    }
    这里得到的baos,就是附件文件。
分享到:
评论
2 楼 fooky 2011-01-05  
我想编码方式编辑一条彩信并发送,如何实现?
1 楼 hackeryk 2010-08-25  
请问一下 我想获取彩信的来信地址,该如何做?

相关推荐

    android 插入彩信数据库代码

    android 插入彩信数据库代码 新建彩信 导入彩信

    短信数据库表名

    短信数据库表名(_id integer 唯一标识,自增,从1开始 date integer 会话最新更新时间 message_count integer 当前会话所包含的消息数量 recipient_ids text 接收者(canonical_addresses表的id)列表,所有接收者...

    短信彩信的收发

    本资源实现了android系统中短信的拦截和显示、彩信的拦截及保存 短信的发送功能,将所有的拦截的彩信数据都存储在自己建立的数据库中。

    安卓短信彩信相关相关-android手机自身模拟发送短信利用的是pdu包一开始时间不对我用更新数据库的方法给调整了....可能对于某些机型会出现错误.rar

    android手机自身模拟发送短信,利用的是pdu包,一开始时间不对,我用更新数据库的方法给调整了....可能对于某些机型会出现错误.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。

    Android高薪之路:Android程序员面试宝典 李宁

    9 3 彩信 9 4 联系人 第10章 多媒体技术 10 1 音频 10 2 视频 10 3 摄像头 10 4 铃声 第11章 2D绘图与动画技术 11 1 绘制基本图形 11 2 图像特效 11 3 路径 11 4 帧 Frame 动画 11 5 补间 Tween 动画 第12章 OpenGL ...

    Android开发案例驱动教程 配套代码

    17.2.1 Android内置的发送短信/彩信功能 450 17.2.2 自己编写发送文本内容的短信 452 17.2.3 自己编写接收文本内容的短信 458 17.2.4 自己编写发送二进制内容的短信 459 17.2.5 自己编写接收二进制内容的短信 ...

    Android Mms之:短信发送流程(图文详解)

    信息的发送,对于Mms应用程序来讲主要就是在信息数据库中创建并维护一条信息记录,真正的发送过程交由底层(Frameworks层)函数来处理。 总体的来讲,当信息创建完成后,对于信息通常有三个去处,一个是放弃这个信息...

    Importer:适用于Android的应用程序,可帮助导入SMS,该应用程序由Sony支持的PC Companion备份

    据我了解的短信/彩信数据库的不同结构的问题。 这就是为什么我尝试制作一些有助于导入您的短信/彩信数据的应用程序的原因。 用法 将mmssms.db复制到手机 Lauch Importer应用程序 通过按导入按钮选择数据库 按下...

    Android一些常用功能的代码

    android一些核心功能程序代码 1、对话框 2、上下文菜单事件 3、选项菜单事件 4、创建上下文菜单 5、创建选项菜单 6、时间选择器 7、进度条 8、数据库绑定 10、发送短信程序 11:查看是否有存储卡插入 12:让某个...

    android开发使用例子

    数据库 显示网页: 1. Uri uri = Uri.parse("http://www.google.com"); 2. Intent it = new Intent(Intent.ACTION_VIEW,uri); 3. startActivity(it); 显示地图: 1. Uri uri = Uri.parse("geo:38.899533,-77....

    Android Mms之:接收信息流程(图文详解)

    信息的接收工作是由底层来完成的,当有一个 新的信息时底层完成接收后会以Intent的方式来通知上层应用,信息的相关内容也包含在Intent当中,Android所支持的信息Intent都定义在android.provider.Telephony.Intents...

    Android Mms之:草稿管理的应用

    当编辑完一条信息后,如果在没有发送的情况下退出...草稿的保存也是针对不同的信息而不同,短信和彩信的流程有所不同。保存短信为草稿WorkingMessage会先取出短信内容,然后开启一个新的线程去做接下来的事,WorkingM

    Contacts:安卓联系人

    Android Contacts List (Android 通讯录) 自己闲着无聊,做个通讯录用用,省的没事总备份通讯录,也不用被第三方软件盗取...短息模块包括短信和彩信,分别对应SMS和MMS数据库。 短息功能: 1.获取sms 2.获取 mms

    J2ME手机高级编程demo

    手机文件系统、网络通信、无线通信(短信通信、彩信通信和蓝牙通信)、底层用户界面应用(游戏开发和电子地图浏览)、多媒体编程(音乐播放器、视频播放器和摄像头视频采集等)、持久化应用、移动商务应用(对象...

    Securecom-Messaging

    我们创建了一个单独的应用程序来支持短信和彩信。 除了电话号码外,还支持使用电子邮件地址作为身份。 支持具有电子邮件地址或电话号码的用户之间的对话。 支持没有电话的设备,例如平板电脑。 支持黑莓设备 ...

    JAVA上百实例源码以及开源项目

    此时此景,笔者只专注Android、Iphone等移动平台开发,看着这些源码心中有万分感慨,写此文章纪念那时那景! Java 源码包 Applet钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这...

    JAVA上百实例源码以及开源项目源代码

    此时此景,笔者只专注Android、Iphone等移动平台开发,看着这些源码心中有万分感慨,写此文章纪念那时那景! Java 源码包 Applet钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这...

    嵌入式系统PDA智能手机设计方案.doc

    现在手机已经不只是用于语 音通信的手持设备,而成为集成了短信、彩信、上网以及移动办公等附加功能的嵌入式 通信平台。 集成了这些功能的手机被称为智能手机。近年,嵌入式处理器的运行速度和功能都有了 很大的提高...

Global site tag (gtag.js) - Google Analytics