I use a broadcastreceiver for getting the result by intent, from a barcode scanner.
The old "apk" still works fine, but after compiling with newest B4a, I receive nothing.
The old "apk" still works fine, but after compiling with newest B4a, I receive nothing.
broadcast:
#Region Module Attributes
#StartAtBoot: false
#End Region
'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Broadcast As BroadCastReceiver
Dim lastintent As Intent
End Sub
Sub Service_Create
Broadcast.Initialize("BroadcastReceiver")
End Sub
Sub Service_Start (StartingIntent As Intent)
Dim DATA As String : DATA = "data"
''Dim SOURCE As String : SOURCE = "source_byte"
Log(StartingIntent.Action)
Log(StartingIntent.ExtrasToString)
If ((lastintent <> StartingIntent) And (Main.bInitPos <> False)) Then
lastintent = StartingIntent
If StartingIntent.Action = "com.sunmi.scanner.ACTION_DATA_CODE_RECEIVED" Then
''Dim typ As String = StartingIntent.GetExtra("com.oem.barcode.type")
Dim barcode As String = StartingIntent.Getextra(DATA)
''Dim encoding As String = StartingIntent.GetExtra("com.oem.barcode.encoding")
''Dim meta As Map
''meta.Initialize
''meta.Put("Type",typ)
''meta.Put("BarCode",barcode)
''meta.Put("Encoding",encoding)
'
'Log("Type="&StartingIntent.GetExtra("com.oem.barcode.type"))
'Log("BarcodeString="&StartingIntent.GetExtra("com.oem.barcode.string"))
'Log("Encodingok="&StartingIntent.GetExtra("com.oem.barcode.encoding"))
'Log(StartingIntent.GetExtra("com.oem.barcode.type"))
'Log(StartingIntent)
''If (Main.EditCity.Visible = True) Then
'' CallSubDelayed(Main,"EditCity_Clear")
''Else
CallSubDelayed2(Main,"ReadPosBarcode",barcode)
''End If
'This starts listening for all broadcasts that has the following string: "android.provider.Telephony.SMS_RECEIVED" and sets the priority to the maximum. (this means it will try to first call this receiver)
'Broadcast.addAction("android.intent.action.bcr.newdata")
End If
End If
Broadcast.SetPriority(2147483647)
Broadcast.registerReceiver(Me) 'here you can add the main action (intent)
End Sub
Sub Service_Destroy
End Sub
Sub BroadcastReceiver_OnReceive (Action As String)
ToastMessageShow(Action,False)
'can only abort when sendOrderedbroadcast is called.
'Broadcast.AbortBroadcast
End Sub