Clear Call Logs

madSac

Active Member
Licensed User
Longtime User
Hey,
I wanted to clear user's call logs on googling i found something like this
Code: Copy
getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI, null, null)
Can anyone help me in using it in B4A ...i think it can be done using reflection lib but how ?
 
Try this:
Code: Copy
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod("getContentResolver")
Dim CONTENT_URI As Object = _
   r.GetStaticField("android.provider.CallLog$Calls", "CONTENT_URI")
r.RunMethod4("delete", Array As Object(CONTENT_URI, Null, Null), _
   Array As String("android.net.Uri", "java.lang.String", "[Ljava.lang.String;")
 
Upvote 0
Thanks for replying.I did one mistake.The original thread is at

http://stackoverflow.com/questions/11406588/how-many-ways-to-delete-call-history-on-android

Code: Copy
Uri uri = Uri.parse("content://call_log/calls");

int d  = getContentResolver().delete(uri, null, null);
//d returns no. of records deleted.


int res = Call_logs.this.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI,"_ID = "+ calls_id_list.get(i),null);
    if (res == 1) {
       // Log delete

    } else {
        // Log not Delete

    }
Please provide conversion for this code.Sorry !!

i used below code but i get an error
Code: Copy
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod("getContentResolver")
Dim CONTENT_URI As Object =  r.RunStaticMethod("android.net.Uri", "parse", Array As Object("content://call_log/calls"), Array As String("java.lang.String"))
Log(r.RunMethod4("delete", Array As Object(CONTENT_URI, Null, Null),   Array As String("android.net.Uri", "java.lang.String", "java.lang.String")))

i get following error
Code: Copy
java.lang.NoSuchMethodException: delete
 
Last edited:
Upvote 0
Try this:
Code: Copy
Sub ClearLogs
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod("getContentResolver")
Dim CONTENT_URI As Object = _
   r.GetStaticField("android.provider.CallLog$Calls", "CONTENT_URI")
r.RunMethod4("delete", Array As Object(CONTENT_URI, Null, Null), _
   Array As String("android.net.Uri", "java.lang.String", "[Ljava.lang.String;"))
end sub

I'm using that, and nothing happens. The code after that line is skipped as if the sub is returns
 
Upvote 0
I see since then you made a contentresolver library and someone said they ported your code to it, but didnt post it...
 
Upvote 0
Got it:
Code: Copy
Sub ClearCallLogs
   Dim CON As ContentResolver, r As Reflector, CONTENT_URI As Object
   CON.Initialize("")
   r.Target = r.GetContext
   r.Target = r.RunMethod("getContentResolver")
   CONTENT_URI = r.GetStaticField("android.provider.CallLog$Calls", "CONTENT_URI")'content://call_log/calls
   CON.Delete(CONTENT_URI, "DURATION >= 0",Null)
   'r.RunMethod4("delete", Array As Object(CONTENT_URI, Null, Null), Array As String("android.net.Uri", "java.lang.String", "[Ljava.lang.String;"))
End Sub
 
Upvote 0
Code: Copy
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod("getContentResolver")
Dim CONTENT_URI As Object =  r.RunStaticMethod("android.net.Uri", "parse", Array As Object("content://call_log/calls"), Array As String("java.lang.String"))
Log(r.RunMethod4("delete", Array As Object(CONTENT_URI, Null, Null),   Array As String("android.net.Uri", "java.lang.String", "[Ljava.lang.String;")))

I´m trying to undestand but I can´t.

In this code where I set the CallLog ID to delete just one log ? ( I get the ID from "CallItem" )


In the original code expect an ID

Code: Copy
int res = Call_logs.this.getContentResolver().delete(android.provider.CallLog.Calls.CONTENT_URI,"_ID = "+ calls_id_list.get(i),null);


I found also a code below but I can´t translate to B4a

Code: Copy
public void DeleteCallById(String idd) {  
    this.getContentResolver().delete(CallLog.Calls.CONTENT_URI,CallLog.Calls._ID + " = ? ",
            new String[] { String.valueOf(idd) });
    }
 
Upvote 0
Hi I write a solution.
You can delete by ID ou Number and seems to be faster then the library "myfirstLib".
If you need to delete many fields you can do your own code and put a "doevents" to not block the cell


Code: Copy
    Dim cl As CallLog
    Dim ci As CallItem
    Dim List_Call As List
    Dim xNum As String
    Dim xRet As Int
    Dim xcursor As Cursor
  
    List_Call.Initialize
    List_Call = cl.GetAll(10)
    ci = List_Call.Get(0)
  
   Log ( "ID: " & ci.Id & " - Numero: " & ci.Number)
   Dim CON As ContentResolver, r As Reflector, CONTENT_URI As Object
   CON.Initialize("")
   r.Target = r.GetContext
   r.Target = r.RunMethod("getContentResolver")
   CONTENT_URI = r.GetStaticField("android.provider.CallLog$Calls", "CONTENT_URI")'content://call_log/calls
'   xRet = CON.Delete(CONTENT_URI, "_ID=" & ci.id ,Null)
   xNum = ci.Number
   xRet = CON.Delete(CONTENT_URI, "NUMBER= ?"    ,Array As String(xNum))
    Log ( "retorno delete: " & xRet )
 
Last edited:
Upvote 0
Back
Top