[Android] content watcher
Intercept short messages. For example, when sending short messages, read them out. When the system's short messages change, shout and send the data to the public message mailbox. Our application observes the public message mailbox through the content observer
Get the contentresolver object and call the function getcontentresolver(),
Call the registercontentobserver (URI, notifyfordescendants, observer) method of the contentresolver object. Parameters: URI object, exact URI (true is not accurate, false is accurate), observer object, contentobserver object
Because contentobserver is an a abstract class, we write an internal class to inherit this abstract class. We must implement the constructor. The handler object of the constructor and the message processor will talk about it later
Define an internal class myobserver to implement the onchange () callback method of the parent class. This method will be called back when the message mailbox changes.
In this callback function, use to get the SMS content, take the last one, and call the movetofirst () pointer of the cursor object to point to the last one
This application also needs permissions
How does the system application make this call? Get the contentresolver object and call the notifychange (URI, observer) method of the contentresolver object through the getcontentresolver () method. The parameter: URI is arbitrarily defined, and observer specifies who handles null by default
Many applications of the system realize notification communication through this public message mailbox mechanism