Android Question My app force close when receivethe sms.

dragonguy

Active Member
Licensed User
Longtime User
here is my code
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim sNotif As Notification
End Sub
Sub Service_Create
    Dim PhoneId As PhoneId
    Dim PE As PhoneEvents
    Dim SI As SmsInterceptor
    SI.Initialize2("SI",999)
    PE.InitializeWithPhoneState("PE", PhoneId)
    sNotif.Initialize
    sNotif.Icon = "icon"

    sNotif.SetInfo("Incoming Call and SMS Record","Service Running...",Main)
    sNotif.Sound = False
    sNotif.Notify(1)
    Service.StartForeground(1,sNotif)
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_Destroy

End Sub

Sub SI_MessageReceived (From AsString, Body AsString) As Boolean
    Log("MessageReceived: From = " & From & ", Body = " & Body)
    Return True
End Sub


Sub PE_PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
    Log("PhoneStateChanged, State = " & State & ", IncomingNumber = " & IncomingNumber)
    Log(Intent.ExtrasToString)
End Sub

my error log
B4X:
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x8000010 (has extras) } in anywheresoftware.b4a.phone.PhoneEvents$SMSInterceptor$2@527ab048
    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:778)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:149)
    at android.app.ActivityThread.main(ActivityThread.java:5061)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
    at dalvik.system.NativeStart.main(Native Method)
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:768)
    ... 10 more
** Activity (main) Resume **

i just wanna to capture the messages to store to database.
 
Last edited:

dragonguy

Active Member
Licensed User
Longtime User
I think the crash is about Android version, current develop phone is kit Kat version. After that I try use Build configuration function to separate code for kit Kat and lower version. Now seem the crash solved.
Erel got any good solution for manage the code for different Android version?
 
Upvote 0
Top