8

I am trying to make a VoIP application and I wanted to know if it is possible to do the following with the Call Logs content provider -

  1. I want to add new Call Log records for the VoIP call along with the call logs for the regular call. How can I add new records to the existing Call logs content provider?

  2. I want to add custom fields to the Call Logs like a session ID and SIP address(name@domain) field. How can I customize the call logs database?

It'll be great if someone can give me an example.

Kara
  • 6,115
  • 16
  • 50
  • 57
Tushar Gupta
  • 1,410
  • 13
  • 22

2 Answers2

10

Regarding the first question, you can use this code to add new records to the existing Call logs content provider:

public static void insertPlaceholderCall(ContentResolver contentResolver, String number){
    ContentValues values = new ContentValues();
    values.put(CallLog.Calls.NUMBER, number);
    values.put(CallLog.Calls.DATE, System.currentTimeMillis());
    values.put(CallLog.Calls.DURATION, 0);
    values.put(CallLog.Calls.TYPE, CallLog.Calls.OUTGOING_TYPE);
    values.put(CallLog.Calls.NEW, 1);
    values.put(CallLog.Calls.CACHED_NAME, "");
    values.put(CallLog.Calls.CACHED_NUMBER_TYPE, 0);
    values.put(CallLog.Calls.CACHED_NUMBER_LABEL, "");
    Log.d(TAG, "Inserting call log placeholder for " + number);
    contentResolver.insert(CallLog.Calls.CONTENT_URI, values);
}

(Code taken from Google Voice Callback for Android)

Remember to add the permissions in the Manifest

<uses-permission
    android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission
    android:name="android.permission.WRITE_CONTACTS"></uses-permission>

Regarding the customization of the call logs database, I do not think is possible.

Roberto Leinardi
  • 10,641
  • 6
  • 65
  • 69
  • Can you help me a little bit? I did exactly same, insert is returning the URI of call log with id, but call log on my phone is not updated. It will be very helpful. – Bhavya Gupta May 02 '21 at 07:10
6

From a standard SDK application, you cannot directly extend or modify the CallLog database or content provider. For an SDK-based VOIP application, you should maintain your own call log.

If you are writing your own firmware for your own device, I am sure there are ways you can modify the call log database.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • If what you say is true, what's your response to Roberto's answer below? Is there any reason it shouldn't work or shouldn't be used? – E-Riz Oct 04 '11 at 14:43
  • @Eric: That answer is for adding calls to the log. I was addressing bullet #2; Roberto addressed bullet #1. My apologies for any confusion. – CommonsWare Oct 04 '11 at 14:48