HI
I use this solution. It works very well on the version targetSdkVersion="19".
https://www.b4x.com/android/forum/t...sms-messages-in-the-background.20103/#content
Unfortunately when compiling the project to the "targetSdkVersion =" 26 "version. The filter does not work.
I use this solution. It works very well on the version targetSdkVersion="19".
https://www.b4x.com/android/forum/t...sms-messages-in-the-background.20103/#content
Unfortunately when compiling the project to the "targetSdkVersion =" 26 "version. The filter does not work.
B4X:
'ACTIVITI (main)
Sub Globals
Private Label1 As Label
Private Label2 As Label
Private Label3 As Label
Private Label4 As Label
end sub
Sub demo
Label3.Text=S1.dane1
Label4.Text=S1.dane2
End Sub
B4X:
'Service module
Sub Process_Globals
Type Message (Address As String, Body As String)
Dim dane1 As String
Dim dane2 As String
End Sub
Sub Service_Create
End Sub
Sub Service_Start(startingIntent As Intent)
If startingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
Dim messages() As Message
messages = ParseSmsIntent(startingIntent)
For i = 0 To messages.Length - 1
Log(messages(i))
Next
End If
Service.StopAutomaticForeground
End Sub
'Parses an SMS intent and returns an array of messages
Sub ParseSmsIntent (in As Intent) As Message()
Dim messages() As Message
If in.HasExtra("pdus") = False Then Return messages
Dim pdus() As Object
Dim r As Reflector
pdus = in.GetExtra("pdus")
If pdus.Length > 0 Then
Dim messages(pdus.Length) As Message
For i = 0 To pdus.Length - 1
r.Target = r.RunStaticMethod("android.telephony.SmsMessage","createFromPdu", _
Array As Object(pdus(i)), Array As String("[B"))
messages(i).Body = r.RunMethod("getMessageBody")
messages(i).Address = r.RunMethod("getOriginatingAddress")
dane1= messages(i).Body
dane2= messages(i).Address
akcja
Next
End If
Return messages
End Sub
Sub akcja
Dim a As Boolean
a=dane1.Contains("Aa1")
If a = True Then
CallSubDelayed(Main,"demo")
StartActivity("main")
StopService(Me)
End If
End Sub