Android Question Problems with SMS Interceptor

GMan

Well-Known Member
Licensed User
The incoming SMS was complete received, i can see the senders numbers and the body (text).
But then the App crashes with following error ( i am using V6.8)

B4X:
MessageReceived: From = +491234567890, Body = This is a test
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x8000010 (has extras) } in anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$2@293a410
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:932)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:207)
    at android.app.ActivityThread.main(ActivityThread.java:5741)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
    at anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$2.onReceive(PhoneEvents.java:398)
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:922)
    ... 7 more

Here is my manifest content:

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.basic4ppc.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
AddManifestText(<uses-feature android:name="android.hardware.location.gps"/>)
AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="secret :-)"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
AddManifestText(<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="23" />
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(s1,
<intent-filter>
    <action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
)
'End of default text.
 

KMatle

Expert
Licensed User
I assume you are using runtime permissions as it is >= sdk 23. I've just tested one of my older apps with sdk 23 and I first came across a similar problem (app was crashing while parsing the sms and I could see it's contents). The solution was easy (at last here):

You must add

B4X:
Sleep(0) 'allow the MessageReceived event to be raised.

directly (!) after the service starts. For me it solved the problem.


B4X:
Sub Service_Start(startingIntent As Intent)
    Sleep(0) 'allow the MessageReceived event to be raised.
    If startingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
        SMSList.Initialize
        ParseSmsIntent(startingIntent)
        For i = 0 To SMSList.size - 1
            Dim SMSMap As Map
            SMSMap=SMSList.Get(i)
            Log(SMSMap.Get("address"))
            Log(SMSMap.Get("body"))
            Log(SMSMap.Get("time"))
            ParseSingleSMS(SMSMap.Get("address"),SMSMap.Get("body"))
        Next
        
    End If
    LogColor("Ready",Colors.Blue)
    Service.StopAutomaticForeground
    StartActivity(Main)
    
End Sub
 
Upvote 0

GMan

Well-Known Member
Licensed User
Thx for your hint - i have to change to newest version of the IDE i think.
Still using 6.8 (no Sleep() function ;-) )

Thougth it would be possible with this, too
 
Upvote 0

GMan

Well-Known Member
Licensed User
I tried - still no Sleep() function ;)
 
Upvote 0

GMan

Well-Known Member
Licensed User
I just tried the sample from that page - the error is still the same
also i read your Update2018 - seems i have to upgrade to the newest version at all
 
Last edited:
Upvote 0
Top