开发者

how to update call logs through android applications

I am trying to access call logs through android application. I have taken data through app and update the value of database but after updating I can't get the updated values in call list.

code I tried below:

Uri allCalls = Uri.parse("content://call_log/calls");
C开发者_如何学运维ursor c = managedQuery(allCalls, null, null, null, null);     
  
if (c.moveToFirst()) {
    do {            
        String callType = "";
        switch (
            Integer.parseInt(c.getString(c.getColumnIndex(Calls.TYPE)))
        ) {
            case 1: callType = "Incoming";
                break;
            case 2: callType = "Outgoing";
                break;
            case 3: callType = "Missed";
        }
     } while (c.moveToNext());
  } 
 
  ContentValues values = new ContentValues();
  values.put("name", "Unknown");
  
  int k = getContentResolver().update(allCalls, values,null, null);
 

I got the integer value for k as how many number of rows updated but in call list I didnt get updated value.

Edit: I am able to insert and delete the call list values and when I check in call list it shows the result as inserting new row or deleting the existing one But when I update the values I can update, it return values as result of update query when I check by clicking callLog list, update value remain for a fraction of second and then old value displaying...

I don't know where I made a mistake, please help me...


Seeing this question is over a year old, I don't know if you're still looking for an answer to this. Thought you'd like to know the answer anyway.

Your code is completely fine, it updates the call record as it is supposed to. But since you're changing just the name, it is unlikely to stick. The name field in the Call Logs is a cached name, as indicated in the Android Documentation, and is probably refreshed every time you view the logs.

If you're just changing the name, the name associated with the number will be refreshed from the Contacts list, and that is why you won't see the updated name in the Logs. Or, you'll see the change until the list is refreshed/updated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜