I know you are tempted to mark this a duplicate but wait, let's go through this again with my detailed (but failed) attempts.
Strategy 1: Algorithm: Answer
The first time the onChange is fired, get the id of the row updated
The next time the onChange is fired again get id of row updated
Match the id
Ignore if same id
Problem with this approach is that it is vulnerable to race conditions. If by the time you get the id of the updated row, onChange has fired for the second time, this Algorithm fails. This originated from my personal experience while testing on slow machines or machines working at peak capacity.
Strategy 2: Algorithm:Answer
Override deliverSelfNotifications() to return true.
This seems promising at first but fails to work. The code I used for reference:
In Main Activity:OnCreate Method I register:
getContentResolver().registerContentObserver(Uri.parse("content://sms"), true, new CtObserver(new Handler()));
Then in a separate Class:
package com.example.testproject;
import android.database.ContentObserver;
import android.os.Handler;
import android.util.Log;
/**
* @author Time Traveller
*/
public class CtObserver extends ContentObserver {
public CtObserver(Handler handler) {
super(handler);
}
public boolean deliverSelfNotifications(){
return true;
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.e("onChange","Fired");
}
}
Why you should contribute to this answer:
Quering SMS content Provider is the only way for Non Default Apps to capture the event for the Sent SMS. But till now I have not found any convincing fully functional answer for this method. So we really need to get some minds on this !!.
Questions:
- What is the functional(non tweaked) way of simply knowing that a SMS was written to the Content Provider only once?
- What is the correct way of using deliverSelfNotifications() in Content Observer Class?
You need not answer all the questions, just tell us anything you know.