This article describes the Android Development implementation method for removing contact call records. Share to everyone for your reference, specific as follows:
1. The source of the content provider responsible for storing call records is under the Contactsprovider project:
Source path:
Com/android/providers/contacts/calllogprovider.java
The databases that are used are:
/data/data/com.android.providers.contacts/databases/contacts2.db
Table name: Calls
There are three types of call logs:
Caller: CallLog.Calls.INCOMING_TYPE (constant value: 1)
Dialed: CallLog.Calls.OUTGOING_TYPE (constant value: 2)
Not answered: CallLog.Calls.MISSED_TYPE (constant value: 3)
View the declaration in the source code:
<provider android:name= "Calllogprovider"
android:authorities= "Call_log"
android:syncable= "false" Android:multiprocess= "false"
android:readpermission= "Android.permission.READ_CONTACTS"
android: writepermission= "Android.permission.WRITE_CONTACTS" >
</provider>
2. Permissions that need to be declared
<uses-permission android:name= "Android.permission.READ_CONTACTS"/>
<uses-permission android:name= " Android.permission.WRITE_CONTACTS "/>
3. The system's call records, is through the contentprovider to share externally
4. Uri
CallLog.Calls.CONTENT_URI: Equivalent to: Uri.parse ("Content://call_log/calls");
5. Check out all records
Contentresolver resolver = Getcontentresolver ();
Resolver.query (CallLog.Calls.CONTENT_URI, NULL, NULL, new string[]{"15101689022"}, NULL);
6. Check all records of a contact (by phone number)
Copy Code code as follows:
Resolver.query (CallLog.Calls.CONTENT_URI, NULL, "number=", New string[]{"15101689022"}, NULL);
7. Check all outstanding phone records for a contact (by phone number)
Copy Code code as follows:
Resolver.query (CallLog.Calls.CONTENT_URI, NULL, "Number=?") and type=3 ", New string[]{" 15101689022 "}, NULL);
8. Delete a contact's last call
/* This code can call Getcontentresolver () directly because it is in the activity. This method is actually defined in the context. * *
Contentresolver resolver = Getcontentresolver ();
/* Here is the knowledge of content providers, in fact, here is directly in the operation of the Android database, very painful * * *
Cursor Cursor = Resolver.query (CallLog.Calls.CONTENT_URI, new string[]{"_id"}, "Number=?" and (type=1 or type=3) ", New string[]{" 15101689022 "}," _id desc, limit 1 ");
if (Cursor.movetofirst ()) {
int id = cursor.getint (0);
Resolver.delete (CallLog.Calls.CONTENT_URI, "_id=", new string[] {id + ""});
For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android Debugging techniques and common problem solving method summary", "Android graphics and image processing skills summary", " Android Multimedia How-to Summary (audio, video, audio, etc), summary of Android Basic components usage, Android View tips Summary, Android layout layout tips and a summary of Android controls usage
I hope this article will help you with the Android program.