转自:http://www.eoeandroid.com/thread-8990-1-1.html
回楼上:先写一个观察者: |
public class SmsObserver extends ContentObserver {
private Context context;
private static final String[] SMS_PROJECTION = new String[] {
"address","person","date","type","body",
};
public SmsObserver(Context context,Handler handler) {
super(handler);
this.context = context;
Log.i("Leo-SmsObserver", "My Oberver on create");
}
public void onChange (boolean selfChange) {
Log.i("SmsObserver", "sms onChange###### ");
}
}
然后在Acitivty或Service里注册这个观察者
getContentResolver().registerContentObserver(Uri.parse("content://sms"),
true, new SmsObserver(this, new Handler()));
当收发短信时,会调用onChange方法