Recently do address book items, need to listen to the deletion of text messages in real-time, the use of the observer contentobserver, strange things happen, when I delete a text message, you can listen to, but when I delete the whole text message, you can't listen to, check a lot of information, Do not have a good solution, by the way spit bad: We come to EoE hair problem, solve the problem, do not say the solution to share the way to everyone ...
OK, first look at the source bar
Com.android.providers.telephony.MmsSmsProvider This class of delete operation source code
@Override
public int Delete (URI Uri, String selection,
string[] Selectionargs) {
Sqlitedatabase db = Mopenhelper.getwritabledatabase ();
Context context = GetContext ();
int affectedrows = 0;
switch (Uri_matcher.match (URI)) {
Case Uri_conversations_messages:
long threadId;
try {
threadId = Long.parselong (Uri.getlastpathsegment ());
} catch (NumberFormatException e) {
log.e (Log_tag, "Thread ID must be a long.");
Break ;
}
affectedrows = Deleteconversation (URI, Selection, Selectionargs);
mmssmsdatabasehelper.updatethread (db, threadId);
Break ;
Case Uri_conversations:
AffectedRows = mmsprovider.deletemessages (context, DB,
selection, Selectionargs, Uri)
+ db.delete ("SMS", Selection, Selectionargs);
//intentionally don ' t pass the selection variable to updateallthreads.
//When we pass in "locked=0" there, the thread would get excluded from
//The selection and not get updated.
mmssmsdatabasehelper.updateallthreads (db, NULL, NULL);
Break ;
Case Uri_obsolete_threads:
affectedrows = Db.delete ("Threads",
"_id not in (SELECT DISTINCT thread_id from SMS" +
"UNION SELECT DISTINCT thread_id from PDU", null);
Break ;
Default:
throw new Unsupportedoperationexception (no_deletes_inserts_or_updates);
}
if ( affectedrows > 0) {
context.getcontentresolver (). Notifychange (Mmssms.content_uri, null);
}
return affectedrows;
}
Note the Red Word section, when the whole session is deleted, the system sends the notification is Mmssms.content_uri, verify:mmssms.content_uri= Uri.parse ("content://mms-sms")
ok~ problem solved in this
I can say that I find the eggs are broken, I can say that everyone can be a little mutual help spirit, please, everyone is knocking code ...
http://www.eoeandroid.com/thread-325408-1-1.html
http://www.eoeandroid.com/thread-325255-1-1.html
Go [Android instance] a solution that uses Contentobserver to listen for messages that are not removed from the SMS session