Android Question Zebra Barcode Scanner and Receiver Module not working

techgreyeye

Member
Licensed User
Longtime User
Hello !

I recently updated one of my apps to target SDK 34 to avoid so many warnings when customers are installing the app. I had to make various changes, but I am left with one unresolved issue.
One customer with a newer Zebra running Android 14 had scanning stop working, and I don't have access to a newer device for debugging (I still have a TC20 running Android 8.1).
Having looked on the forums, I decided to process the intents using a Receiver module rather than a Service using BroadcastReceiver. I am not receiving any barcode scans in the Receiver module.

I've attached a minimal project showing the issue. There is a variable useService in Main which can be set to true or false.

The intent on the Zebra is configured as it is because the app was initially written by somebody else who copied an example and released it without changing them. Could the naming be the issue? Am I missing something from the manifest?

I'd really appreciate if anyone could have a look and see where it is going wrong.

Thank you :)
 

Attachments

  • ZebraApp.zip
    10.1 KB · Views: 39

techgreyeye

Member
Licensed User
Longtime User
Can you post the relevant code?

Have you checked the device documentation? Maybe it only works with dynamic intent filters.

Hi Erel,

Service using BroadcastReceiver:
#Region  Service Attributes
    #StartAtBoot: False
    
#End Region

' 401

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim BC As BroadCastReceiver

End Sub

Sub Service_Create
    'the parameters may discovered with Log(intent.extrasToString) in the OnReceive Method
    BC.Initialize("BC")

End Sub

Sub Service_Start (StartingIntent As Intent)
    'category and action must match the settings in datawedge app
    BC.addCategory("intent_kategorie")
    BC.addAction("scanner_intent")
    BC.SetPriority(20000000)
    RegisterReceiver("scanner_intent")
    Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub

Sub Service_Destroy

End Sub

Sub BC_OnReceive (action As String, o As Object)
    Dim intent As Intent = o
    Log("Service : " & intent.Action)

    Dim code As String
    If intent.HasExtra("com.symbol.datawedge.data_string") Then
        code = intent.GetExtra("com.symbol.datawedge.data_string")
    Else If intent.HasExtra("com.motorolasolutions.emdk.datawedge.data_string") Then
        code = intent.GetExtra("com.motorolasolutions.emdk.datawedge.data_string")
    Else
        Return
    End If
    CallSubDelayed2(Main,"process_barcode", code)
End Sub

Private Sub RegisterReceiver(action As String)
    BC.registerReceiver(action)
End Sub

Receiver Module:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
    Log("Receiver : " & StartingIntent.Action)

    Dim code As String
    If StartingIntent.HasExtra("com.symbol.datawedge.data_string") Then
        code = StartingIntent.GetExtra("com.symbol.datawedge.data_string")
    Else If StartingIntent.HasExtra("com.motorolasolutions.emdk.datawedge.data_string") Then
        code = StartingIntent.GetExtra("com.motorolasolutions.emdk.datawedge.data_string")
    Else
        Return
    End If
    CallSubDelayed2(Main,"process_barcode", code)
End Sub
Manifest:
'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: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="35"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
AddReceiverText(zebrareceiver,
<intent-filter>
    <category android:name="intent_kategorie" />
    <action android:name="scanner_intent" />
</intent-filter>)
SetReceiverAttribute(zebrareceiver, android:exported, "true")

Have you checked the device documentation? Maybe it only works with dynamic intent filters.

I can't see anything in the device documentation about dynamic intent filters. There is information about configuring intent filters your apps manifest, which I think is the "non-dynamic" method, so can't imagine it's this causing the issue.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
it looks like you have your receiver both dynamically and contextually declared at the same time.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
I've removed service from the app (as attached), still not getting the intent.
I don't see any action in the manifesto.

B4X:
AddReceiverText(zebrareceiver,
<intent-filter>
    <category android:name="scanner_intent" />
    <category android:name="intent_kategorie" />
</intent-filter>)

Sample:
B4X:
AddReceiverText(zebrareceiver,
<intent-filter>
    <action android:name="com.zebra.scan.ACTION" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>)

note:
In the DataWedge application of your Zebra TC20, the profile must be configured with Intent Delivery in Broadcast Intent mode and the Intent Action as com.zebra.scan.ACTION.

See:
 
Last edited:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
To listen for the action of the Intent you defined in DataWedge

test: zebrareceiver
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
  
End Sub

'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
    Log("Receiver : " & StartingIntent.Action)

    If StartingIntent.Action = "com.zebra.scan.ACTION" Then
        Dim barcode As String = StartingIntent.GetExtraString("com.symbol.datawedge.data_string")
        Dim bartype As String = StartingIntent.GetExtraString("com.symbol.datawedge.label_type")
        CallSubDelayed2(Main, "Barcode_Scanned", barcode)
    End If
End Sub

Manifest:
B4X:
AddReceiverText(zebrareceiver,
<intent-filter>
    <action android:name="com.zebra.scan.ACTION" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
I've removed service from the app (as attached), still not getting the intent.
the library you are using is dynamic. nothing goes in the manifest.
 
Upvote 0

techgreyeye

Member
Licensed User
Longtime User
I don't see any action in the manifesto.

B4X:
AddReceiverText(zebrareceiver,
<intent-filter>
    <category android:name="scanner_intent" />
    <category android:name="intent_kategorie" />
</intent-filter>)

Sample:
B4X:
AddReceiverText(zebrareceiver,
<intent-filter>
    <action android:name="com.zebra.scan.ACTION" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>)

note:
In the DataWedge application of your Zebra TC20, the profile must be configured with Intent Delivery in Broadcast Intent mode and the Intent Action as com.zebra.scan.ACTION.

See:

Thanks for the response.

Manifest is like this now, I had made a mistake when playing around with the app, there was an action previously. I don't think it actually matters what the intent action and category are set to, as long as the settings are consistent between DataWedge and the app (I have an app working in production with "scanner_intent" for the action, and "intent_kategorie" for the category - but only the broadcast receiver service version, not the receiver module version).

Manifest:
'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: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="35"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
AddReceiverText(zebrareceiver,
<intent-filter>
    <action android:name="com.zebra.scan.ACTION"/>
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>)

I've updated the intent action and category in DataWedge to match the manifest in the receiver version and the BroadcastReceiver settings in the service version (both attached). I'm still getting scans with the service version and not the receiver version. I'm puzzled.
 

Attachments

  • ZebraAppReceiver.zip
    9.1 KB · Views: 14
  • ZebraAppService.zip
    9.3 KB · Views: 13
Upvote 0

techgreyeye

Member
Licensed User
Longtime User
the library you are using is dynamic. nothing goes in the manifest.

Thanks for the reply. I'm not sure what you mean. I have 2 versions, one using a service module with BroadcastReceiver, which doesn't have anything related in the manifest, and one attempting to use a Receiver module, which does have entries in the manifest.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Thanks for the reply. I'm not sure what you mean. I have 2 versions, one using a service module with BroadcastReceiver, which doesn't have anything related in the manifest, and one attempting to use a Receiver module, which does have entries in the manifest.
you had said you were using the broadcastreceiver library. that library uses a dynamic receiver (so it's not declared in the manifest). you no longer use that library, so my comment no longer applies.
 
Upvote 0

techgreyeye

Member
Licensed User
Longtime User
Compare the generated AndroidManifest.xml with the manufacturer instructions.

I can't see anything wrong, I was wondering about this though :

Manifest:
<receiver android:name=".zebrareceiver" android:exported="true">
<intent-filter>
<action android:name="com.zebra.scan.ACTION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
</application>

The receiver name in the generated manifest is .zebrareceiver, but my module name is zebrareceiver
 
Upvote 0
Top