Android contentobserver-blocks and deletes text messages

Source: Internet
Author: User

Class smsdbobserver extends contentobserver {

Private context CTX;

Public smsdbobserver (handler, context CTX ){
Super (handler );
This. CTX = CTX;
}

@ Suppresswarnings ("static-access ")
Public void onchange (Boolean selfchange ){
Super. onchange (selfchange );
Try {
// Prepare the URI address of the system SMS inbox
Uri uri = URI. parse ("content: // SMS/inbox ");
// Query all text messages in the inbox
Cursor isread = CTX. getcontentresolver (). Query (Uri, null, "Read =" + 0, null, null );
While (isread. movetonext ()){
// String phone = isread. getstring (isread. getcolumnindex ("Address"). Trim ();
String body = isread. getstring (isread. getcolumnindex ("body"). Trim ();
Log. I ("bindphone", "Get the SMS ---->" + body );
If (body! = NULL & (body. indexof ("Vimi ")! =-1) & (body. indexof (App. bindphonenum )! =-1 )){
Log. I ("bindphone", "Get the validate SMS ---->" + body );
Int id = isread. getint (isread. getcolumnindex ("_ id "));

Palmmessagerservice. instance. validatebindphone (App. bindphonearea, app. bindphonenum );
CTX. getcontentresolver (). Delete (URI. parse ("content: // SMS"), "_ id =" + id, null );
Holdsms = false;
Break;
}
}
} Catch (exception e ){
E. printstacktrace ();
}
}

}

// Start listening for verification text messages
Handler handler = NULL;
If (smsobserver = NULL) {// create a content listener SMS listener
Try {
Handler = new handler ();
} Catch (exception e ){
Log. I ("bindphone", "Get handler error:" + E. getmessage ());
}
Smsobserver = new smsdbobserver (handler, this );
}
If (! Holdsms) {// register the content listener and specify the content listener to listen to the data changes of that Uri
Log. I ("bindphone", "Start monitor the SMS ");
This. getcontentresolver (). registercontentobserver (
Uri. parse ("content: // SMS/"), true, smsobserver );
Holdsms = true;
}

Related Article

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.