final String      SMS_URI_MMS = "content://mms"; //此处查询的表是pdu表
ContentResolver MMScr         = context.getContentResolver();
Uri             MMSuri        = Uri.parse(SMS_URI_MMS);
Cursor          MMScursor     = null;
MMScursor = MMScr.query(MMSuri, null, null, null, null);//查出所有彩信
if (MMScursor == null){return;
}
if (!MMScursor.moveToFirst()){//跳转到第一行,如果失败跳出方法,成功则进入do while循环return;
}
do {JSONObject jsonObject=new JSONObject();String id=MMScursor.getString(MMScursor.getColumnIndex("_id"));// 获取pdu表里 彩信的idString phonenumber=getAddressNumber(context,id);int timess=MMScursor.getInt(MMScursor.getColumnIndex("date") );long timesslong=(long) timess*1000;//彩信获取的时间是以秒为单位的。Date             d                 = new Date(timesslong);String           date              = dateFormat.format(d);String sub=MMScursor.getString(MMScursor.getColumnIndex("sub"));//获取彩信主题try {if (!TextUtil.isEmpty(sub)){sub=new String(sub.getBytes("ISO8859_1"), "UTF-8");//测试时发现乱码https://www.xuebuyuan.com/2198269.html 从该博文找到的解决方法    }else {sub=" ";}} catch (UnsupportedEncodingException e) {e.printStackTrace();}final String SMS_URI_MMS_PART="content://mms/part"; //从part表 获取彩信详情String selectionPart = "mid=" + id;// part表mid字段即为 pdu表 _id 字段ContentResolver Scr         = context.getContentResolver();//String[]        projection = new String[]{"_id", "address", "person", "body", "date", "type","protocol"};Uri             uri        = Uri.parse(SMS_URI_MMS_PART);Cursor          cursor     = Scr.query(uri, null,selectionPart, null, null); //查询 part 指定mid的数据if (cursor==null){continue;}else {if (cursor.moveToFirst()){//游标移至第一行成功 则进入do while 循环 一个mid查询出来的结果可能是多条,彩信的结构也     //是多层的 有点类似html的结构do {String type = cursor.getString(cursor.getColumnIndex("ct"));//part表 ct字段 标识 此part内容类型,彩信始末:application/smil;如果是文本附件:text/plain;//图像附件:jpg:image/jpeg,gif:image/gif;音频附件:audio/mpegif ("text/plain".equals(type)) {String data = cursor.getString(cursor.getColumnIndex("_data"));// 当此part类型为文本附件时,通过_data拿到文本附件地址String body;//彩信文本if (data != null) {//附件地址不为空// implementation of this method belowString partId = cursor.getString(cursor.getColumnIndex("_id"));body = getMmsText(context,partId);try {jsonObject.putOpt("content", EmojiParser.removeAllEmojis(sub+body));//因为要存数据库 删掉所有emoji} catch (JSONException e) {e.printStackTrace();}} else {//附件地址为空时通过text获取文本//如果是彩信始末,为彩信的SMIL内容;如果是文本附件,为附件内容;如果是视频、音频附件,text为空body = cursor.getString(cursor.getColumnIndex("text"));try {jsonObject.putOpt("content", EmojiParser.removeAllEmojis(sub+body));} catch (JSONException e) {e.printStackTrace();}}}}while (cursor.moveToNext());}}Logger.w("duanxin","彩信="+jsonObject.toString() );jsonArray.put(jsonObject);
}while (MMScursor.moveToNext());
private static String getMmsText(Context context, String id) {//此处id 为part表的_id 字段Uri partURI = Uri.parse("content://mms/part/" + id);InputStream is = null;StringBuilder sb = new StringBuilder();try {try {is = context.getContentResolver().openInputStream(partURI);if (is != null) {InputStreamReader isr = new InputStreamReader(is, "UTF-8");BufferedReader reader = new BufferedReader(isr);String temp = reader.readLine();while (temp != null) {sb.append(temp);temp = reader.readLine();}}} catch (FileNotFoundException e) {e.printStackTrace();}} catch (IOException e) {}finally {if (is != null) {try {is.close();} catch (IOException e) {}}}return sb.toString();
}private static String getAddressNumber(Context context,String id) {//此处id 也是pdu表的_id字段String selectionAdd = new String("msg_id=" + id);String uriStr = MessageFormat.format("content://mms/{0}/addr", id);Uri uriAddress = Uri.parse(uriStr);Cursor cAdd = context.getContentResolver().query(uriAddress, null,null, null, null);String name = null;if (cAdd.moveToFirst()) {do {String number = cAdd.getString(cAdd.getColumnIndex("address"));if (number != null) {try {Long.parseLong(number.replace("-", ""));name = number;} catch (NumberFormatException nfe) {if (name == null) {name = number;}}}} while (cAdd.moveToNext());}if (cAdd != null) {cAdd.close();}return name;
}

https://stackoverflow.com/questions/3012287/how-to-read-mms-data-in-android?answertab=active#tab-top

本文大部分都是摘抄的国外大神的

Android 获取彩信文本内容及 发送时间 发送人相关推荐

  1. android 文字选中朗读,Android开发之文本内容自动朗读功能实现方法

    本文实例讲述了Android开发之文本内容自动朗读功能实现方法.分享给大家供大家参考,具体如下: Android提供了自动朗读支持.自动朗读支持可以对指定文本内容进行朗读,从而发生声音:不仅如此,An ...

  2. android的发音功能实现,Android开发之文本内容自动朗读功能实现方法

    本文实例讲述了Android开发之文本内容自动朗读功能实现方法.分享给大家供大家参考,具体如下: Android提供了自动朗读支持.自动朗读支持可以对指定文本内容进行朗读,从而发生声音:不仅如此,An ...

  3. Android 获取应用的安装时间及更新时间

    Android 获取应用的安装时间及更新时间 在工作时遇到一个需求,就是获取应用的安装时间,本来我觉的这个应该是不能获取到的.觉得应用在安装时,并不是由应用自身控制的.所以就直接回复对方说取不到.但是 ...

  4. android studio怎么输出文本,Android Studio 如何获取 text文本内容

    1.找到目录的main先建立assets格式的文件夹 2.再把需要读取的txt 文件放入到该文件夹下(名字随意),这里取 list.txt. 文件内容 格式如下 3.读取文本内容 工具代码 /** * ...

  5. android:获取富文本图片和使用Jsoup抓取腾讯新闻网页数据

    先看效果: 获取富文本中的图片 抓取腾讯新闻中的图片 首先引入要使用的jar包 compile 'jp.wasabeef:glide-transformations:2.0.2'compile 'or ...

  6. ABAP 类方法获取长文本内容

    区别于READ_TEXT函数获取长文本在于,这是把长文本直接拼接成一个字符串输出,READ_TEXT是装进一个内表输出.用于不同场景, DATA:lv_str  TYPE STRING. " ...

  7. js获取富文本内容长度_js富文本实现

    转载来源:https://www.cnblogs.com/xiaohuochai/p/5884206.html 一说起富文本,人们第一印象就是像使用word一样,在网页上操作文档.实际上差不多就是这样 ...

  8. android 字符串 时间格式化,Android 获取年月日时分秒 格式化指定时间字符串

    1.获取Android系统当前时间年月日 时分秒(24小时制) //获取当前时间 Time time=new Time(); time.setToNow(); Log.i("cp" ...

  9. android看彩信自动退出,直接发送彩信?为什么很多安卓的应用都有权限,而我却不知道...

    原标题:直接发送彩信?为什么很多安卓的应用都有权限,而我却不知道 在我们在下载一些软件的时候,安装后如果不加注意,可能会漏掉很多重要的安全问题.比如,一些app会取得直接发送彩信的权限,并且我们也不会 ...

最新文章

  1. Linux下锁用户与解锁问题
  2. 4.3.4 网络地址转换NAT
  3. 什么是T4级数据中心
  4. 经典面试题 之 子数组之和最大值
  5. Eclipse 设置SVN忽略文件
  6. 计算机科学 在职双证,计算机专业在职研究生如何获得双证?
  7. mysql 联合索引 性能_mysql:联合索引及优化
  8. Windows下CodeBlocks安装及配置注意事项
  9. mysql启动和常用语法实战回顾
  10. 如何在 Mac 上的网站上使用 Touch ID 作为密码?
  11. Latex 编译错误 Error Launching Console Application XeLaTeX ...系统找不到指定的文件。
  12. java 回调函数传值_说明Java的传递与回调机制的代码示例分享
  13. 选择排序的时间复杂度
  14. cad动态块制作翻转_cad动态块拉伸制作方法,单开门动态块制作教程具体分析
  15. 达梦管理工具连接数据库服务器时提示:错误号 6001 网络通信异常
  16. ubuntu apt-get安装或卸载软件时出现了python-minimal等错误问题的解决方法
  17. 第三章 SQL命令 ALTER USER
  18. 怎么制作证件照电子版?安利下面这三款软件给你
  19. SPOJ ACPC13——Increasing Shortest Path
  20. 获取域内所有DNS解析记录

热门文章

  1. 输入输出管理:假脱机技术(SPOOLING)
  2. w i ndows,解释计算 机Windows的学习英语(10页)-原创力文档
  3. 安卓APP自动更新实现
  4. [数据挖掘] 朴素贝叶斯 以及西瓜集特征工程
  5. 牛年第一瓜!阿里女员工被初中文化男子骗走500多万!开豪车连骗12名女性,被判无期!...
  6. 手机计算机错误格式,手机内存卡提示文件格式错误怎么办【解决方法】
  7. 压缩包 zip RAR 7z 密码破解常用的几种方法
  8. TypeScript学习总结
  9. 教你如何攻克Kotlin中泛型型变的难点(下篇)
  10. 黑暗星空中的秘密——《黑暗森林》简评