读写系统数据库中的短信:ContentResolver
来源:互联网 发布:网址导航手机版 源码 编辑:程序博客网 时间:2024/06/08 15:11
/**
* 读取系统短信方法
* @param view
*/
public void readSms(View view){
ContentResolver resolver=getContentResolver(); //创建ContentResolver对象,得到内容解析者
Uri uri= Uri. parse("content://sms/"); //全部短信的uri
Cursor cursor = resolver.query(uri, null, null, null, null); //得到结果集
while(cursor.moveToNext()){
String address=cursor.getString(cursor.getColumnIndex("address" )); //得到地址
long date=cursor.getLong(cursor.getColumnIndex( "date")); //得到时间
String body=cursor.getString(cursor.getColumnIndex("body" )); //内容
String type=cursor.getString(cursor.getColumnIndex("type" )); //短信类型
SmsBean smsBean= new SmsBean();
smsBean.setAddress(address);
smsBean.setBody(body);
smsBean.setDate(date);
smsBean.setType(type);
tv.setText(smsBean.toString());
/*if("1".equals(type)){
System.out.println("接收到的短信:");
}else{
System.out.println("发送的短信");
}
System.out.println("号码:"+address+" 时间:"+date+" 内容:"+body); //打印短信信息
*/
}
cursor.close();
}
---------------------------------------------------------------------------------------------------
public void testBatch() throws Exception {
ContentResolver resolver = getContext().getContentResolver();
ArrayList<ContentProviderOperation> list = new ArrayList<ContentProviderOperation>();
ContentProviderOperation operation1 = ContentProviderOperation.newInsert(rawContactsUri)
.withValue( "_id", null)
.build();
ContentProviderOperation operation2 = ContentProviderOperation.newInsert(dataUri)
.withValueBackReference( "raw_contact_id", 0) // 把同组第一个操作的结果作为值
.withValue( "mimetype", "vnd.android.cursor.item/name" )
.withValue( "data1", "CR")
.build();
ContentProviderOperation operation3 = ContentProviderOperation.newInsert(dataUri)
.withValueBackReference( "raw_contact_id", 0)
.withValue( "mimetype", "vnd.android.cursor.item/phone_v2" )
.withValue( "data1", "131999888888")
.build();
ContentProviderOperation operation4 = ContentProviderOperation.newInsert(dataUri)
.withValueBackReference( "raw_contact_id", 0)
.withValue( "mimetype", "vnd.android.cursor.item/email_v2" )
.withValue( "data1", "cr@hotmail.com")
.build();
list.add(operation1);
list.add( operation2);
list.add(operation3);
list.add(operation4);
resolver.applyBatch( "com.android.contacts", list);
}
}
- 读写系统数据库中的短信:ContentResolver
- 4.1短信备份,利用系统短信内容提供者ContentResolver
- ContentResolver之短信读取
- adb pull 系统短信数据库
- ContentResolver查询系统音乐文件
- 短信读写
- Android中的ContentResolver应用
- Android中的ContentResolver应用
- Android 中的 ContentResolver
- android中的ContentResolver
- 使用ContentResolver读取通话记录与短信记录
- Android黑科技,读取用户短信+修改系统短信数据库
- Android监听系统短信数据库变化-提取短信内容
- 读写sql数据库中的图片
- 自定义数据库 -- ContentProvider和ContentResolver
- ContentResolver读取系统联系人数据
- ContentResolver访问android系统图库
- android黑科技之读取用户短信+插入短信到系统短信数据库
- Uart的自动流控制
- android下UriMatcher类使用介绍
- 一种风场的建立vc++
- 使用ContentResolver操作ContentProvider中的数据
- C语言编译过程中编译器都干了些什么?
- 读写系统数据库中的短信:ContentResolver
- 《Java语言程序设计(基础篇)》读书笔记(四)
- Codeforces Round #206 (Div. 1)--Vasya and Digital Root 啊啊啊 啊....感觉我的智商为0........
- 第7周项目2-两数正差
- 读取联系人:ContentResolver
- android下内容观察者: ContentObserver
- spring框架下的第一个实例
- scrollview2
- IOCP