Reading SMS

RilleR

Member
Licensed User
Longtime User
When i read Textmessages with the Library "phone" and object "SmsMessages" and it works fine in the log, i can see all messages the last 7 days if i use

Dim SmsMessages1 As SmsMessages
Dim List1 As List
List1 = SmsMessages1.GetAllSince(DateTime.Add(DateTime.Now, 0, 0, -7))
For i = 0 To List1.Size - 1
Dim Sms As Sms
Sms = List1.Get(i)
Log(Sms)
Next

But it looks like i can't get all messages from a specific Adress (Phonenumber), so i tried to use Basic4android - Phone
instead. It seemes that this function supports the "Adress" object.

Using the string

Dim SmsMessages1 As Sms
Dim List1 As List
List1 = SmsMessages1.Address, "1234567"
For i = 0 To List1.Size - 1
Dim Sms As Sms
Sms = List1.Get(i)
Log(Sms)

I get a syntax error upon compilation, what am i missing here...:sign0085:
 

genesi

Active Member
Licensed User
Longtime User
try this
B4X:
Dim SmsMessages1 As Sms
Dim List1 As List

List1 = SmsMessages1.Address, "1234567"  'This is a your desire ;)
List1 = SmsMessage1.getAll  
'now we have all SMS  in List1
For i = 0 To List1.Size - 1    ' Browse the List
    Dim Sms As Sms
    Sms = List1.Get(i)    ' single SMS
    ' Test
    if Sms.Address= "1234567" then     
         Log(Sms)
    end if
next
 
Last edited:
Upvote 0

RilleR

Member
Licensed User
Longtime User
try this
B4X:
Dim SmsMessages1 As Sms
Dim List1 As List

List1 = SmsMessages1.Address, "1234567"  'This is a your desire ;)
List1 = SmsMessage1.getAll  
'now we have all SMS  in List1
For i = 0 To List1.Size - 1    ' Browse the List
    Dim Sms As Sms
    Sms = List1.Get(i)    ' single SMS
    ' Test
    if Sms.Address= "1234567" then     
         Log(Sms)
    end if
next

Thankyou for your suggestion and help genesi, i got it to work this way..


Dim SmsMessages1 As SmsMessages
Dim List1 As List

List1 = SmsMessages1.GetAllSince(DateTime.Add(DateTime.Now, 0, 0, -14))
For i = 0 To List1.Size - 1
Dim Sms As Sms
Sms = List1.Get(i)
If Sms.Address = "1234567" Then
Log(Sms)
End If
Next

:sign0060:
 
Last edited:
Upvote 0

RilleR

Member
Licensed User
Longtime User
I wonder if some kind soul would lite to tell me why this example don't work.
It gives me an error upon compilation "Unknown member: Address"


Regards
Richard


try this
B4X:
Dim SmsMessages1 As Sms
Dim List1 As List

List1 = SmsMessages1.Address, "1234567"  'This is a your desire ;)
List1 = SmsMessage1.getAll  
'now we have all SMS  in List1
For i = 0 To List1.Size - 1    ' Browse the List
    Dim Sms As Sms
    Sms = List1.Get(i)    ' single SMS
    ' Test
    if Sms.Address= "1234567" then     
         Log(Sms)
    end if
next
 
Upvote 0

RilleR

Member
Licensed User
Longtime User
This code is wrong. There are two types of objects SmsMessages and Sms.
SmsMessages - Provides access to the stored messages.
Sms - Represents a single message.

Basic4android - Phone

Yes i know its wrong, and am sorry for not seeing what might be obvious.
I have read the phone library and understands that Sms and Smsmessages is two different objects.

I Get Smsmessages to work, but i want to read the last single message from a specific sender. In my example here i get the log to show the messages from one sender, but the label show other messages.

I have a feeling that the reason is that SmsMessages and Sms in my example use the same List.

B4X:
Dim SmsMessages1 As SmsMessages 
Dim List1 As List

List1 = SmsMessages1.GetAllSince(DateTime.Add(DateTime.Now , 0, 0, -14))
For i = 0 To List1.Size - 1
Dim Sms As Sms
Sms = List1.Get(i)
If Sms.Address = "1234567" Then 
Log(Sms)
End If
Next 
lblPos.text  = (Sms)
 
Upvote 0

RilleR

Member
Licensed User
Longtime User
Yes i know its wrong, and am sorry for not seeing what might be obvious.
I have read the phone library and understands that Sms and Smsmessages is two different objects.

I Get Smsmessages to work, but i want to read the last single message from a specific sender. In my example here i get the log to show the messages from one sender, but the label show other messages.

I have a feeling that the reason is that SmsMessages and Sms in my example use the same List.

B4X:
Dim SmsMessages1 As SmsMessages 
Dim List1 As List

List1 = SmsMessages1.GetAllSince(DateTime.Add(DateTime.Now , 0, 0, -14))
For i = 0 To List1.Size - 1
Dim Sms As Sms
Sms = List1.Get(i)
If Sms.Address = "1234567" Then 
Log(Sms)
End If
Next 
lblPos.text  = (Sms)


I got it to work this way, have no idea if this is the best, but i get the newest sms from a specific sender.

B4X:
Dim SmsMessages1 As SmsMessages 
Dim List1 As List

List1 = SmsMessages1.GetAllSince(DateTime.Add(DateTime.Now , 0, 0, -1))
For i = 0 To List1.Size - 1
Dim Sms1 As Sms

Sms1 = List1.Get(i)
If Sms1.Address = "1234567" Then
List1.SortType ("Date", True)
Log(Sms1)
lblPos.text  = (Sms1)

End If
Next

End Sub
 
Last edited:
Upvote 0
Top