3

I would like to update the CallLog.Calls.TYPE field of the first entry in the Android Call Log from MISSED to INCOMING. I have read books, the developers reference and googled this to death and am reasonably sure that my code is correct. However, when I actually make the call to update(), the result is that no record is updated. My code sample is below.

Before you ask:
- I have permissions for WRITE_CONTACTS
- The record to be updated (0) does exist
- I have tried this on both a DroidX (Verizon) and a Samsung Galaxy (AT&T) - I have tried various other, longer forms of this code with same result

Can someone please help with this?

    ContentValues newValues = new ContentValues();
    newValues.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
    newValues.put(CallLog.Calls.DURATION, 50);
    int result = OsmoService.context.getContentResolver().update(
    ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, 0), 
    newValues,null,null);
Tejus Prasad
  • 6,322
  • 7
  • 47
  • 75
user600222
  • 81
  • 1
  • 7

3 Answers3

1
ContentValues cv = new ContentValues();
cv.put(CallLog.Calls.NUMBER,"7070770"); // contact number

cv.put(CallLog.Calls.TYPE,1); // type

cv.put(CallLog.Calls.DURATION, 120); // duration in second


getContentResolver().insert(CallLog.CONTENT_URI, cv);
Rajesh Satvara
  • 3,842
  • 2
  • 30
  • 50
1

If you update your code above and replace the line:

ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, 0)

with this line:

Uri.parse("content://call_log/calls")

It works. I don't know why, but something is not correct with the content URI.

example:

ContentValues newValues = new ContentValues();
newValues.put(CallLog.Calls.TYPE, CallLog.Calls.INCOMING_TYPE);
newValues.put(CallLog.Calls.DURATION, 50);
int result = OsmoService.context.getContentResolver().update(
    Uri.parse("content://call_log/calls"), 
    newValues,
    null,
    null);
Camille Sévigny
  • 5,104
  • 4
  • 38
  • 61
  • 1
    Thanks for the response! After pouring over traces, I actually found where my error was. I had been assuming that in the following, xxx was a row number: "content://call_log/calls/xxx". However, from the URIs returned from inserting a new entry, I found that xxx actually needed to be the _ID field of the record. All works fine now. – user600222 Apr 28 '11 at 12:28
0

for example CallLog.Calls.CACHED_NAME

private void updateCachedName(int id, @NonNull String name) {

    ContentValues contentValues = new ContentValues();
    contentValues.put(CallLog.Calls.CACHED_NAME, name);

    if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_CALL_LOG) == PackageManager.PERMISSION_GRANTED) {

        getContext().getContentResolver().update(CallLog.Calls.CONTENT_URI, contentValues, CallLog.Calls._ID + "=" + id, null);
    }
}
hsyn tr
  • 1
  • 1