Content observer of Android

Source: Internet
Author: User

A common requirement is to display the content on the interface when a new text message is sent. Content observer is used here. It is to let your program monitor text messages. If the content changes, you can get it. What I did on the text message side was that when his data changed, he told a public text message memory zone. He said, "My data has changed! Then, use the text message content provider to get the text message content to the public memory area, and your program will get it again. Here is a simple sample code:

ContentResolver resolver = getContentResolver (); Uri uri = Uri. parse ("content: // sms/"); resolver. registerContentObserver (uri, true, new MyObserver (new Handler (); Cursor cursor = resolver. query (uri, new String [] {"address", "date", "type", "body"}, null); cursor. moveToFirst (); String address = cursor. getString (0); String body = cursor. getString (3); System. out. println (address + "---" + body); cursor. close ();


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.