Go [Android instance] a solution that uses Contentobserver to listen for messages that are not removed from the SMS session

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.