Mobile phone call record is saved in the database, location:/data/data/com.android.providers.contacts/databases/calllog.db, table name: Calls
There is a Type field in this table, and the property value is a constant value:
- Call: CallLog.Calls.INCOMING_TYPE (constant value: 1)
- Dialed: CallLog.Calls.OUTGOING_TYPE (constant value: 2)
- Missed: CallLog.Calls.MISSED_TYPE (constant value: 3)
This is the most common, number fields represent phone numbers, and some other fields do not describe them.
Add Permissions
<android:name= "Android.permission.READ_CONTACTS"/> < Android:name = "Android.permission.WRITE_CONTACTS"/> <android:name= "Android.permission.WRITE_CALL_LOG"/>
The first two permissions are read/write contacts, the last one is the right to write the call record, this permission I did not add, but in the operation of the call record, Android Studio recommended to add this permission, or the red line will be drawn, but does not affect the program run
Writing code
The system is shared out through the ContentProvider (content provider).
Uri
CallLog.Calls.CONTENT_URI equivalent to: Uri.parse ("Content://call_log/calls"); You can use any of them.
Get Content Parser
Contentresolver resolver = Getcontentresolver ();
The Getcontentresolver () method is a method of the content class
Action Content Parser
In fact, the operation and operation of SQLite almost the same way, such as delete operations:
New String[]{number});
Deletes all records for a given number and can also add conditions (such as type=1) to delete incoming call records for a given number
All call records that query a contact can be used (Query method)
NULL New null);
Although the phone number records were deleted, there could be delays, so we queried whether the phone number table changed
Add a class inheritance Contentobserver in mainactivity to see if the phone number table has changed, and if so, delete the number again
/*** Contentobserver Context Viewer*/ classCalllogobserverextendsContentobserver {PrivateString number; PublicCalllogobserver (String number, Handler Handler) {Super(handler); This. Number =Number ; } /*** If the call history changes * *@paramSelfchange*/@Override Public voidOnChange (BooleanSelfchange) { Super. OnChange (Selfchange); Deletecalllog (number); } }
Don't forget to call this class, get the parser through Getcontentresolver (), then call the Registercontentobserver method, and note that the last variable gives the Calllogobserver class that was written.
true New New Handler ()));
Android Notes-Delete the system call log