android--短信查询
sms主要结构:
_id => 短消息序号 如100
thread_id => 对话的序号 如100
address => 发件人地址,手机号.如+8613811810000
person => 发件人,返回一个数字就是联系人列表里的序号,陌生人为null
date => 日期 long型。如1256539465022
protocol => 协议 0 SMS_RPOTO, 1 MMS_PROTO
read => 是否阅读 0未读, 1已读
status => 状态 -1接收,0 complete, 64 pending, 128 failed
type => 类型 1是接收到的,2是已发出
body => 短消息内容
service_center => 短信服务中心号码编号。如+8613800755500
查询短信是通过contentprovider实现的
例如 查询收件箱:managedQuery(Uri.parse("content://sms/inbox");
查询发件箱 managedQuery(Uri.parse("content://sms/send");
Java代码
public final static String SMS_URI_ALL = "content://sms/"; //0
public final static String SMS_URI_INBOX = "content://sms/inbox";//1
public final static String SMS_URI_SEND = "content://sms/sent";//2
public final static String SMS_URI_DRAFT = "content://sms/draft";//3
public final static String SMS_URI_OUTBOX = "content://sms/outbox";//4
public final static String SMS_URI_FAILED = "content://sms/failed";//5
public final static String SMS_URI_QUEUED = "content://sms/queued";//6
例子:
view plaincopy to clipboardprint?package com.shao.sms;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class ReadSMSActivity extends Activity {
/** Called when the activity is first created. */
private static final String LOG_TAG = "Sms Query";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
super.onCreate(savedInstanceState);
TextView tv = (TextView) findViewById(R.id.text);
tv.setText("");
tv.setText(getSmsAndSendBack());
}
/**
* 读取短信
* @return
*/
public String getSmsAndSendBack()
{
String[] projection = new String[] {
"_id",
"address",
"person",
相关新闻>>
- 发表评论
-
- 最新评论 更多>>