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;
}