6

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 this?

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 if that is a predefined class or user defined class.

Your help will be very appreciated. Thank you

Manaus
  • 407
  • 5
  • 9
Sanjay Joshi
  • 2,036
  • 6
  • 33
  • 48

2 Answers2

12

May this help you:

Add this permission in your AndroidManifest.xml:

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

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);
Karthikeyan
  • 196
  • 2
  • 10
Bhavin Nattar
  • 3,189
  • 2
  • 22
  • 30
  • You spent time on it, Thank you very much. But your answer seems to adding a new contact. What I actually want is inserting a call log (Incoming call log). Thanks buddy – Sanjay Joshi Jul 30 '13 at 06:18
-1

Check this link for call log accessing

this

Permission for this access is

<uses-permission android:name="android.permission.READ_CALL_LOG" />
Community
  • 1
  • 1
Abhinav Singh Maurya
  • 3,313
  • 8
  • 33
  • 51