Hello everyone,
I'm working on an old app made in B4A that runs on a Zebra barcode reader. I need to implement barcode reading via intent.
I tried using BroadcastReceiver, first with a static declaration (manifest + receiver module) and then dynamically via the library. Only with the dynamic approach does the event fire correctly, but when I try to read the intent extras I get an error.
I couldn't find any documentation on how to correctly handle the dynamic receiver event, so the problem is probably just the parameter syntax, but I can't figure it out.
I'm absolutely sure about the intent action name and the extra key to retrieve, because the same values work correctly in MAUI and Kotlin.
Any help would be greatly appreciated, thanks!
EDIT:
i was reading all the answer in https://www.b4x.com/android/forum/threads/broadcastreceiver.12493/page-3#posts
At the page 3 is show which are the correct parameters for OnReceive sub, so i correct the routine and now it works
I'm working on an old app made in B4A that runs on a Zebra barcode reader. I need to implement barcode reading via intent.
I tried using BroadcastReceiver, first with a static declaration (manifest + receiver module) and then dynamically via the library. Only with the dynamic approach does the event fire correctly, but when I try to read the intent extras I get an error.
I couldn't find any documentation on how to correctly handle the dynamic receiver event, so the problem is probably just the parameter syntax, but I can't figure it out.
I'm absolutely sure about the intent action name and the extra key to retrieve, because the same values work correctly in MAUI and Kotlin.
Any help would be greatly appreciated, thanks!
dynamic BroadcastReceiver:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private BroadCastReceiver As BroadCastReceiver
End Sub
Sub Activity_Resume
BroadCastReceiver.Initialize("BroadCastReceiver")
BroadCastReceiver.registerReceiver("com.dw.ACTION")
End Sub
Sub BroadCastReceiver_OnReceive (FirstTime As Boolean, Intent As Intent)
Log("Intent: " & Intent.Action)
Log(Intent.ExtrasToString) ' Error here - no ExtrastoString method find
End Sub
ErrorLog:
Error occurred on line: 71 (Main)
java.lang.RuntimeException: Method: ExtrasToString not found in: android.content.Intent
at anywheresoftware.b4a.shell.Shell$MethodCache.getMethod(Shell.java:985)
at anywheresoftware.b4a.shell.Shell.getMethod(Shell.java:644)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:731)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at com.rootsoft.broadcastreceiver.BroadCastReceiver$1.onReceive(BroadCastReceiver.java:110)
at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1580)
at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7747)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
EDIT:
i was reading all the answer in https://www.b4x.com/android/forum/threads/broadcastreceiver.12493/page-3#posts
At the page 3 is show which are the correct parameters for OnReceive sub, so i correct the routine and now it works
Last edited: