calllog and callitem

corsaro

Member
Licensed User
googling, I have found this code to delete call logs. How can I write a similar one on b4a ?

Thanks in advance for helping me.

B4X:
try {
    String strNumberOne[] = {number};
    Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, CallLog.Calls.NUMBER + "=? ", strNumberOne, "");
    boolean bol = cursor.moveToFirst();
    if (bol) {
        do {
            int idOfRowToDelete = cursor.getInt(cursor.getColumnIndex(CallLog.Calls._ID));                            
            getContentResolver().delete(Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, String.valueOf(idOfRowToDelete)), "", null);
        } while (cursor.moveToNext());
    }
} catch (Exception ex) {
    System.out.print("Exception here ");
}
 
Last edited:

corsaro

Member
Licensed User
After reading some tutorials about eclipse (b4a is better then eclipse ;) , and after making a small change in original code, I found this code on eclipse works, and deletes last log in calllogs on my galaxy ACE 2.3.5, for a specific number in call logs.

B4X:
try {
         Toast.makeText(getApplicationContext(), "eseguito", Toast.LENGTH_SHORT).show();
            String strNumberOne[] = { "+44numbertodelete" };
            Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, CallLog.Calls.NUMBER + " = ? ", strNumberOne, "");
            boolean bol = cursor.moveToFirst();
            if (bol) {
                do {
                    int idOfRowToDelete = cursor.getInt(cursor.getColumnIndex(CallLog.Calls._ID));
                    this.getContentResolver().delete(CallLog.Calls.CONTENT_URI,String.valueOf(idOfRowToDelete),null); // this line works and deletes the log
                   
                } while (cursor.moveToNext());
            }
        } catch (Exception ex) {
           Toast.makeText(getApplicationContext(), "non eseguito", Toast.LENGTH_SHORT).show();
           System.out.print("Exception here ");
        }
      
      
      
    }
      

}
But when trying to make a library for B4A, following exactly your tutorial, when I write the code, eclipse tells me there is an error:
the methot getContentResolver() is undefinied for the type MyFirsLib.




Can someone with more experience then me ( I use B4A by 4 days, and eclipse by 1 day) help me to make this small library?
Thanks in advance
 
Last edited:

thedesolatesoul

Expert
Licensed User
make it ba.context.getContentResolver and pass ba as a parameter to the method (it will be invisible).

Like:
B4X:
public static boolean SaveSMS(BA ba, String filepath)
  {

   Cursor cursor1 = ba.context.getContentResolver().query(mSmsinboxQueryUri, new String[] { "_id", "thread_id", "address", "person", "date", "body", "type" }, null, null, null);
}
 

Theera

Well-Known Member
Licensed User
When I generate the javadoc, on the folder I have just 1 file: MyFirstLib.xml
I have not the jar file.

Every suggestion is appreciated.
regards
You must select from menu and then export file,You will have jar file

I' m sorry ,I forget to see all
 
Last edited:

corsaro

Member
Licensed User
hey, i am also looking for delete a callitem from calllog , can you please share your lib ?

thank you very much
enjoy it

usage is very simple.

B4X:
Sub Process_Globals
Dim mfl As MyFirstLib
End Sub


Sub Button1_Click

mfl.deletecalllogs("+440000000000") ' where +44000000000 is a string with the number to be deleted from calllogs

End Sub
 

Attachments

Last edited:

fanfalveto

Active Member
Licensed User
with this you can delete all callog items using MyFisrtLib
B4X:
Dim reg As MyFirstLib
Dim sta,aa,sto,num As String
Dim aaa As CallLog
Dim ll As List
  ll=aaa.GetAll(0)
      For i =0 To ll.Size-1 
             aa=ll.Get(i)
             sta=aa.IndexOf("Number=")+7
              sto=aa.IndexOf(",CachedName=")
              num=aa.SubString2(sta,sto)
                 If num<>"" Then
                          try
                            reg.DeleteCallLogs(num)
                            catch
                          end try
                 End If
        Next
Log("fin")
if calllog log list is so big you must wait for a long time.Thank you for this libray :sign0098:
 

omidaghakhani1368

Well-Known Member
Licensed User
Hi.
I use referer library for delete calllog but not deleted.
example when i dial *0* and then run activity for delete it but not delete and not get error
 

DonManfred

Expert
Licensed User
Top