Android Notes-Delete the system call log

Source: Internet
Author: User

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:

    1. Call: CallLog.Calls.INCOMING_TYPE (constant value: 1)
    2. Dialed: CallLog.Calls.OUTGOING_TYPE (constant value: 2)
    3. 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

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.