Hi...
I have a simple sms send / receive test program. The receive intent is as per https://www.b4x.com/android/forum/t...cepting-sms-messages-in-the-background.20103/
It works perfectly on one phone - Samsung S8, Android 9; but the intent fails to trigger on another phone - Huawei P20.
b4a v 9.50
Any suggestions as to how to debug this situation?
Thanks!
I have a simple sms send / receive test program. The receive intent is as per https://www.b4x.com/android/forum/t...cepting-sms-messages-in-the-background.20103/
It works perfectly on one phone - Samsung S8, Android 9; but the intent fails to trigger on another phone - Huawei P20.
b4a v 9.50
Any suggestions as to how to debug this situation?
Thanks!
manifest:
...
AddPermission(android.permission.SEND_SMS)
AddPermission(android.permission.READ_PHONE_STATE)
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(sms1,
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)
service module:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type Message (Address As String, Body As String)
End Sub
Sub Service_Create
Log("hello")
End Sub
Sub Service_Start (StartingIntent As Intent)
Log(StartingIntent)
ToastMessageShow(StartingIntent, True)
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
' Sleep(2)
Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
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")
Next
End If
Return messages
End Sub
Sub Service_Destroy
End Sub
Last edited: