我想觀察sent
和received
短信在我的應用。接收短信工作正常,但發送短信時有問題。當用戶同時發送多個SMS(羣SMS)時,會跳過一些SMS(onChange()中沒有日誌)。另外,當觀察到的光標正在更新兩次時,onChange()
會被調用兩次。那麼,有誰能告訴我這裏有什麼問題。我怎樣才能在發送的短信中獲得所有發送的短信詳細信息。下面是我觀察發送和接收短信的代碼。ContentObserver的的onChange()跳過一些短信羣發集團短信
onChange()
方法實現,
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.d(getClass().getSimpleName(), "onChanged called");
Cursor cursor = mContext.getContentResolver().query(Uri
.parse("content://sms"), null, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
Log.d("Message Body and ID ",cursor.getString(cursor
.getColumnIndex("body")));
}
}
}
而且我refered一些鏈接/使用deliverSelfNotifications()
返回true受限onChange()
被稱爲兩倍堅持的答案,但是這也不能正常工作。它仍然被調用兩次。
@Override
public boolean deliverSelfNotifications() {
return true;
}
下面是我的logcat輸出,當我發出4消息從模擬器/設備 AAAA,BBBB,CCCC,DDDD,它只是給了我細節的最後兩條消息,第一兩點才跳過。
03-12 18:51:19.809: DEBUG/MyContentObserver(1354): onChanged called
03-12 18:51:21.458: DEBUG/MyContentObserver(1354): onChanged called
03-12 18:51:22.648: DEBUG/MyContentObserver(1354): onChanged called
03-12 18:51:25.508: DEBUG/MyContentObserver(1354): onChanged called
03-12 18:51:28.568: DEBUG/MyContentObserver(1354): onChanged called
03-12 18:51:28.812: WARN/dalvikvm(103): JNI: pin count on array 0x40051200 ([C) is now 11
03-12 18:51:28.841: WARN/dalvikvm(103): JNI: pin count on array 0x40051200 ([C) is now 11
03-12 18:51:28.841: WARN/dalvikvm(103): JNI: pin count on array 0x40051200 ([C) is now 11
03-12 18:51:28.841: WARN/dalvikvm(103): JNI: pin count on array 0x40051200 ([C) is now 11
03-12 18:51:30.348: DEBUG/dalvikvm(103): GREF has increased to 601
03-12 18:51:31.798: DEBUG/dalvikvm(189): GREF has increased to 501
03-12 18:51:32.529: DEBUG/dalvikvm(103): GC freed 8501 objects/577704 bytes in 447ms
03-12 18:51:32.998: DEBUG/dalvikvm(189): GC freed 13158 objects/515104 bytes in 324ms
03-12 18:51:33.538: DEBUG/MyContentObserver(1354): onChanged called
03-12 18:51:33.768: WARN/KeyCharacterMap(189): No keyboard for id 0
03-12 18:51:33.778: WARN/KeyCharacterMap(189): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
03-12 18:51:35.194: DEBUG/Message Body and ID(1354): Cccc
03-12 18:51:35.548: DEBUG/MyContentObserver(1354): onChanged called
03-12 18:51:37.658: DEBUG/MyContentObserver(1354): onChanged called
03-12 18:51:38.308: DEBUG/Message Body and ID(1354): Ddd
正如你所看到的,我只在logcat輸出中獲得了Cccc和Dddd。所以,任何人都可以給我解決方案/爲什麼會發生這種情況,我能做些什麼來獲得前兩條消息。
@Cancer我登錄並檢查光標永遠不能爲null,它總是'cursor.moveToFirst()'返回true。 – 2012-03-13 05:21:00