Android Question how get SMS code number

Douglas Farias

Expert
Licensed User
Longtime User
Hi All.
i have a simple question.
I m using this tutorial to get a sms and read this.
https://www.b4x.com/android/forum/t...cepting-sms-messages-in-the-background.20103/

the result is like this
[Address=28908, Body=Código de Verificação: 204797, IsInitialized=false]

how can i get only the code of a string?
this is a sequence of 6 numbers, It will never change, there will always be 6 numbers in sequence.

but the text can change, where is "Código de Verificação:", Probably this phrase will be changed.
How can I get the sequence of 6 numbers independently if the "Código de Verificação:" text changes or not?

substring2 will not work here if the text "Código de Verificação:" changes


thx all
 

Douglas Farias

Expert
Licensed User
Longtime User
ok, i made this

B4X:
    If StartingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
        Dim messages() As Message
        messages = ParseSmsIntent(StartingIntent)
        Private codigo As String = ""
        For i = 0 To messages.Length - 1
           
           
            Private s1 As String = messages(i).Body
            Dim Matcher1 As Matcher
            Matcher1 = Regex.Matcher("\d+", s1)
            Do While Matcher1.Find
                If Matcher1.Match.Length = 6 Then
                    codigo = Matcher1.Match
                End If
            Loop
       
        Next
       
        If codigo.Length = 6 Then
            CallSubDelayed2(Main,"Recebe_Codigo",codigo)
        End If
       
       
    End If

here is the code, if help someone.

thx
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…