I. Content Observer
* Notify content provider of changes
GetContext (). Getcontentresolver (). Notifychanges (Uri,null); Null indicates that there are no fixed receivers
* Write an observer in other applications and register an instance
Getcontentresolver (). Registercontentobserver (Uri,true,observer); The host data observed by the URI, true means that as long as the host matches, observer represents the specific observer
Example: SMS Bug
1. First write a myobserver inheritance contentobserver, overriding the OnChange method:public class myobserver extends Contentobserver { private context context; public myobserver (Context context, handler handler) { super (handler); this.context = context; } @Override public void OnChange (Boolean selfchange, uri uri) { Super.onchange (Selfchange, uri); // fields in the SMS table read : The  1 representative has read, 0 represents the field in the Unread // SMS table type : 2 represents the information that the monitored machine sends out, 1 represents the information received by the monitored device // gets the content parser contentresOlver recolver = context.getcontentresolver (); / / query detection of the machine's system SMS Cursor cursor = Recolver.query (uri, new string[] { "address", "body", "type", "date"  } , null, null, "Date desc"); cursor.movetofirst () ; //Get SMS Message String Address = cursor.getstring (0) ; string body = cursor.getstring (1) ; int type = cursor.getint (2) ; long date = Cursor.getlong (3)  ; &NBSp; if (TYPE == 2) { string d = new SimpleDateFormat ("yyyy mm month DD Day  HH:MM:SS"). Format (New date (Date)) ;        SYSTEM.OUT.PRINTLN ("The detected machine sent the message: address:" + address + " content:" + body + "Time :" + d ); toast.maketext (context, "detected the machine sent the message: address:" + address + " content:" + body + "Time :" + d, 0). Show () ; } if (type == 1) { &nBsp String d = new simpledateformat ("yyyy mm month DD Day  HH:MM:SS"). Format (New date (Date))  ;            SYSTEM.OUT.PRINTLN ("The detected machine receives information: Address: " + address + " content: " + body + " Time : " + d ); toast.maketext (context, " The detected machine received the information: address: " + address + " content: " + body + " Time : " + d, 0). Show () ; } }}
2. write an observer in other applications and register an instance
Uri uri = uri.parse ("content://sms");//Monitored host
Getcontentresolver (). Registercontentobserver (URI, True, new Myobserver (This, new Handler ()));
This article is from the "Android Notes" blog, so be sure to keep this source http://2585211.blog.51cto.com/10044233/1665225
Content Viewer (a simple phone SMS bug)