Trainer sub-project (4) security guard-blacklist interception using content providers to delete call records and provider call records
In the previous section, we talked about deleting a call record, but a bug is that it will first appear in the call record, and then disappear, which is not good for the user experience, therefore, we need to use the content provider to observe the changes in the call records.
① Get a content manager first
getContentResolver().registerContentObserver(uri, true, new CallLogObserver( incomingNumber,new Handler()));
2. Then, you can assign a value to the Url through the calllog provided by the system.
Uri uri = Uri. parse ("content: // call_log/CILS"); you can also write CallLog. CILS. content_url is not written in this way. It is convenient for me to write a url directly.
③ Define an observer to perform operations.
Private class CallLogObserver extends ContentObserver {private String incomingNumber; public CallLogObserver (String incomingNumber, Handler handler) {super (handler); this. incomingNumber = incomingNumber;} @ Overridepublic void onChange (boolean selfChange) {Log. I (TAG, "the database content has changed, resulting in call records"); getContentResolver (). unregisterContentObserver (this); deleteCallLog (incomingNumber); super. onChange (selfChange );}}
Then, stop the call.
EndCall (); // The remote service method running in another process. After the method is called, the call record may not be generated yet.
That is, the method for hanging up the phone number written in the previous section.