最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android content provider 短信,Android

网站源码admin10浏览0评论

android content provider 短信,Android

android content provider 短信,Android

1. 读写短信 示例代码

均需要先获得读写短信的权限

读取短信代码

public void click(View view){

//1.利用内容提供者 中间人 获取用户的短信数据.

ContentResolver resolver = getContentResolver();

Uri uri = Uri.parse("content://sms/"); //根据分析 代表的是所有的短信的路径

Cursor cursor = resolver.query(uri, new String[]{"address","date","body","type"}, null, null, null);

StringBuffer sb = new StringBuffer();

while(cursor.moveToNext()){

String address =cursor.getString(0);

String date = cursor.getString(1);

String body = cursor.getString(2);

String type = cursor.getString(3);

System.out.println(address+"--"+date+"---"+body+"---"+type);

sb.append(address+"--"+date+"---"+body+"---"+type);

sb.append("\n");

}

cursor.close();

tv.setText(sb.toString());

}

写短信代码

public void click(View view){

ContentResolver resolver = getContentResolver();

Uri uri = Uri.parse("content://sms/");

ContentValues values = new ContentValues();

values.put("address", "95533");

values.put("type", "1");

values.put("body", "公安局给您的建设银行赚了100,000,000.00");

values.put("date",System.currentTimeMillis());

resolver.insert(uri, values);

}

发布评论

评论列表(0)

  1. 暂无评论