Android Question Last incomming call - phone library

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

please, it is possible to know last incomming call? I am trying to find something on forum and I have found nothing. This is the reason why I am asking.

Best regards
p4ppc
 

bsnqt

Active Member
Licensed User
Longtime User
Modify the following code as per your need.

B4X:
Sub Read_CallLog

    ' Incoming Call = 1
    ' Outgoing Call = 2
    ' Missed Call = 3
  
    Dim myCallLog As CallLog
    Dim myList As List
    Dim myitem As CallItem
    myList = myCallLog.GetAll(0)
  
    If myList.Size > 0 Then
  
        For i = 0 To myList.Size -1
            If myList.Get(i) <> Null Then
                myitem = myList.Get(i)
                Log(myitem.Number & " " & myitem.CallType)
            End If
        Next

    End If
  
End Sub
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
Actually for your need you can add something similar to this:

B4X:
If myitem.CallType = 1 then 
Log(myitem.Number)
Exit
End If

(You don't need to go thru all the call log)
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
bsnqt,

thank you very much. It is functioned. It is very good, thank you.

Please, can I get advice?
With your solution I can get list of numbers, but how can i get last missed call? It is some speciál function for this?

Thank you very much
p4ppc
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
The link given by DonManfred is the idea from what you can start with (using PhoneStateChanged). I just would like to add that you should pay attention to Erel's advice on that post: you have to wait for some seconds before looking for the missed call. In another word, if you check the Call Log immediately during or right after the incoming call finishes, then you may not see the missed call. Erel said 20 seconds, but for my case I think I only need around 3 - 5 seconds.

In my earlier post, in the code snippet the missed call type is 3 (myitem.CallType = 3)
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
It is Solved,

thank you very much friends.

The last missed call is first number in the list when you use filter myitem.CallType = 3

Best regards
p4ppc
 
Upvote 0
Top