系统短信库的一些用法
来源:互联网 发布:数控程序员考试题 编辑:程序博客网 时间:2024/06/01 10:27
1、查询所有短信,按发件人进行分组
Cursor mCursor = managedQuery(Uri.parse("content://sms"), new String[] {"_id,address,date,read,status,type,body,count(address) as " + "totleCount from (select _id,substr(address,4) as address,date,read,status,type,body " + "from sms where address like \"+86%\" union select _id,address,date,read,status,type,body " + "from sms where address not like \"+86%\") r group by r.address order by r.date desc --"}, null, null, null);
2、删除一个联系人的所有短信会话,包括+86的号码
/** * 删除一个联系人的所有短信会话,包括+86的号码 * @param phone */ public int deleteMsgSession(Context context, String phone) { String phoneBytitle = ""; if (!phone.startsWith("+86")) { phoneBytitle = "+86" + phone; } else { phoneBytitle = phone.substring(3); } Cursor cursor = context.getContentResolver() .query(Uri.parse("content://sms"), new String[] {"distinct thread_id"}, "address = ? or address = ?", new String[] {phone, phoneBytitle}, null); List<String> list = new ArrayList<String>(); if (null != cursor) { if (cursor.moveToFirst()) { do { int thread_id = cursor.getInt(0); list.add(String.valueOf(thread_id)); } while (cursor.moveToNext()); } } if (null != cursor) { cursor.close(); cursor = null; } int size = list.size(); if(size == 0) { return -1; } else { int num = 0; for (int i = 0; i < size; i++) { int res = context.getContentResolver().delete(Uri.parse("content://sms/conversations/" + list.get(i)), null, null); num = num + res; }// System.out.println("sms_num:" + num); return num; } }
3、向系统库插入短信、版本不同插入的字段有所区别
/** * 将发送的短信保存到系统短信库中 */ private void foreverSendMsg(String content) { ContentValues values = new ContentValues(); //系统SDK的版本号 String sdkVersion = android.os.Build.VERSION.SDK; try { // 发送时间 values.put("date", System.currentTimeMillis()); // 阅读状态 values.put("read", 1); // 送达号码 values.put("address", phoneNumberTextView.getText().toString()); // 送达内容 values.put("body", content); //SDK为2.1时,插入的字段 if(ConstValue.SDK_VERSION == Integer.valueOf(sdkVersion)) { values.put("status", -1); values.put("type", 2);// values.put("locked", 0); } else { // 设置可见 values.put("seen", 1); } getContentResolver().insert(Uri.parse("content://sms/sent"), values); } catch (Exception e) { e.printStackTrace(); } finally { values = null; }
- android系统短信库的一些用法
- 系统短信库的一些用法
- 文章标题 Android系统广播的发送短信和接收短信的一些用法
- linux 系统定时器的一些用法
- 激活系统的短信应用
- 一些短信
- 一些有用的系统存储过程及用法
- linux系统find命令一些用法,没有xargs的
- 一些有用的系统存储过程及用法
- 一些有用的系统存储过程及用法
- 调用打电话和发短信及intent一些其他用法 !
- 系统短信 自定义短信
- 一些猜密的短信!转
- 关于短信网关的一些知识
- cmpp短信开发的一些资料
- 短信和彩信相关的一些书籍
- 短信模块一些bug的修改
- 整人及搞笑的一些笑话短信
- Android 实现图片反转
- Android 利用cursor来进行排序
- libnids ip 重组
- windows 系统Android模拟器联网设置
- nyoj 37 回文字符串
- 系统短信库的一些用法
- 写个小程序来比对两个目录下的不同文件
- Android openfire插件开发
- Android 说说钟表控件
- android 模拟器 实现 打电话 发短信的模拟状态
- 从xml中改变checkBox大小和形状
- Android 数字签名学习笔记
- Android 桌面组件【app widget】 进阶项目--心情记录器
- Android里五种 Toast方式