Dear experts,
Happy New Year to everyone.
Please help to look at my problem:
- I use PhoneStateListener to catch an incoming number (<-- successful)
- When there is an incoming call, I use the caller's number to search in the phone inbox ( <-- successful)
- If there is a received SMS in the inbox (sent by the caller that is making the call), I use the personID of this SMS to look back into the contacts list to find out the contact with same personID, using Contacts.GetById (<-- PROBLEM IS HERE, as the PersonId from SMS is not the same person in Contacts, having the same Id number)
- I checked the log and can see that with the same sms.personId (from the SMS sender?), it gives me a totally different person in the Contacts. They are 2 different persons. Why?
Happy New Year to everyone.
Please help to look at my problem:
- I use PhoneStateListener to catch an incoming number (<-- successful)
- When there is an incoming call, I use the caller's number to search in the phone inbox ( <-- successful)
- If there is a received SMS in the inbox (sent by the caller that is making the call), I use the personID of this SMS to look back into the contacts list to find out the contact with same personID, using Contacts.GetById (<-- PROBLEM IS HERE, as the PersonId from SMS is not the same person in Contacts, having the same Id number)
- I checked the log and can see that with the same sms.personId (from the SMS sender?), it gives me a totally different person in the Contacts. They are 2 different persons. Why?
B4X:
'================================================
Dim SmsMessages1 As SmsMessages
Dim smsList As List
Dim myContacts As Contacts2
'================================================
Sub PSL2_onCallStateChanged (State As Int, incomingNumber As String)
Dim mySms As Sms
smsList = SmsMessages1.GetAllSince(DateTime.add(DateTime.Now, 0, 0, -90))
incomingNumber = ParseRawPhone(incomingNumber)
For i = 0 To smsList.Size - 1
mySms = smsList.Get(i)
If mySms.Address.EndsWith(incomingNumber) Then
Dim callerid As Int = mySms.PersonId
Log(callerid) ' <-- I know the Sms is from JOHN, here the callerid gives me id = 201
' ============= Check If the person with id 201 in the Contacts Is JOHN? ============ '
Dim callercontact As Contact
callercontact = myContacts.GetById(callerid, True, False)
Log(callercontact.DisplayName) ' <-- NO, in the contacts the person with Id 201 is totally different, 201 is giving MARY
' ============= So what is JOHN's Id in the contacts, I want to check it ============ '
Dim mlist As List
mlist = myContacts.FindByName("JOHN", True, True,False)
callercontact = mlist.Get(0) ' <--- This gives me a totally different Id for JOHN, it it 210 (not 201)
End If
Next
End Sub
Sub ParseRawPhone(s As String) As String
Dim sb As StringBuilder
sb.Initialize
For i = 0 To s.Length - 1
If IsNumber(s.CharAt(i)) Then sb.Append(s.CharAt(i))
Next
Return sb.ToString.SubString(4)
End Sub
Last edited: