您的位置:首页 > 移动开发 > Android开发

Android开发之短信

2014-09-25 22:19 162 查看
1. sms主要结构:

  

  _id:短信序号,如100

  

  thread_id:对话的序号,如100,与同一个手机号互发的短信,其序号是相同的

  

  address:发件人地址,即手机号,如+86138138000

  

  person:发件人,如果发件人在通讯录中则为具体姓名,陌生人为null

  

  date:日期,long型,如1346988516,可以对日期显示格式进行设置

  

  protocol:协议0SMS_RPOTO短信,1MMS_PROTO彩信

  

  read:是否阅读0未读,1已读

  

  status:短信状态-1接收,0complete,64pending,128failed

  

  type:短信类型1是接收到的,2是已发出

  

  body:短信具体内容

  

  service_center:短信服务中心号码编号,如+8613800755500

2.短信的Uri存放位置

String SMS_URI_ALL="content://sms/";

String SMS_URI_INBOX="content://sms/inbox";

String SMS_URI_SENT="content://sms/sent";

String SMS_URI_DRAFT="content://sms/draft";

String SMS_URI_OUTBOX="content://sms/outbox";

String SMS_URI_FAILED="content://sms/failed";

String SMS_URI_QUEUED="content://sms/queued";

3. 实例

1)添加权限

2)
private Uri SMS_inBox=Uri.parse("content://sms/");
public void getSMS()
{
ContentResolver cr=getContentResolver();
Cursor cursor=cr.query(SMS_inBox, null, null, null, null);
String msg="";

while(cursor.moveToNext())
{
String number=cursor.getString(cursor.getColumnIndex("address"));
String name=cursor.getString(cursor.getColumnIndex("person"));
String date=cursor.getString(cursor.getColumnIndex("date"));
String _id=cursor.getString(cursor.getColumnIndex("_id"));
String thread_id=cursor.getString(cursor.getColumnIndex("thread_id"));
String protocol=cursor.getString(cursor.getColumnIndex("protocol"));
String read=cursor.getString(cursor.getColumnIndex("read"));
String status=cursor.getString(cursor.getColumnIndex("status"));
String type=cursor.getString(cursor.getColumnIndex("type"));
String service_center=cursor.getString(cursor.getColumnIndex("service_center"));
String body=cursor.getString(cursor.getColumnIndex("body"));
msg+= "短信序号:"+_id+"\n"+
"对话序号:"+thread_id+"\n"+
"号码"+number+"\n"+
"联系人:"+name+"\n"+
"日期:"+date+"\n"+
"协议:"+protocol+"\n"+
"是否阅读:"+read+"\n"+
"状态:"+status+"\n"+
"类型:"+type+"\n"+
"短信中心:"+service_center+"\n"+
"内容:"+body+'\n';
}
tx.setText(msg);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: