我已经用发送消息的观察者定义了以下服务。问题是发送消息时,没有调用 onChange() 方法,请告诉我为什么?
谢谢
public class countService extends Service {
ContentResolver contentResolver;
MyContentObserver Observer;
Uri sms_content = Uri.parse("content://sms/sent");
public Cursor cursor;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
contentResolver = getBaseContext().getContentResolver();
Observer = new MyContentObserver();
contentResolver.registerContentObserver(sms_content, true, Observer);
super.onCreate();
}
private class MyContentObserver extends ContentObserver {
public MyContentObserver() {
super(null);
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.d("BOOOOOOOOOOOOOOOOOO", "c");
Cursor cursor = contentResolver.query(sms_content, null, null,
null, null);
cursor.moveToFirst();
String type = cursor.getString(cursor.getColumnIndex("type"));
Log.d("THEMESSAGE", type);
}
}
}