Sanjay Joshi Sanjay Joshi - 9 months ago 40
Android Question

Writing call log in an Android device

I have created a fake caller, And One place I'm stuck is writing the call logs.

Can someone explain how to write a call log and what permissions are required for the same.

I found an answer at How can I update the contents of an entry in the Call Log? But in that answer the term

OsmoService
is not defined. I'm not able to understand is that a predefined class or user defined class.

Your help will be very appreciated. Thank you

Answer Source

May this help you:

Add this permission in your `AndroidManifest.xml:

<uses-permission
    android:name="android.permission.READ_CALL_LOG"></uses-permission>
<uses-permission
    android:name="android.permission.WRITE_CALL_LOG"></uses-permission>

Code:

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, "");
context.getContentResolver().insert(CallLog.Calls.CONTENT_URI, values);