2

We are currently using a zebra device for company asset management so we are developing a small prototype android app to scan RFID tags. I've read from the data wedge API that the app can get scanned output has an intent broadcast.

But the app is unable to receive any intents.

Device : Zebra MC33

Data wedge version : 7.3

I've tried using the following

Profile Settings:

Intent Action : my.prototype.app.SCAN
Intent Delivery Type: Broadcast Intent.
Intent Category: Default.
Added to Associated Apps

AndroidManifest.xml

    <receiver
        android:name=".ScanIntentReceiver"
        android:enabled="true"
        android:exported="true" />

ScanIntentReceiver.kt

abstract class ScanIntentReceiver : BroadcastReceiver() {

    abstract fun onReceiveScan(data: ScannerOutput)

    override fun onReceive(p0: Context?, p1: Intent?) {
        Timber.d("S1: Broadcast Scan Intent Received.")
        p0?.let { context ->
            p1?.let { intent ->
                when (intent.action) {
                    BuildConfig.intentAction -> {
                        try {
                            val data = parseData(intent, context)
                            Timber.d("Data received: $data")
                            onReceiveScan(data)
                        } catch (ex: Exception) {
                            Timber.d("Parsing error")
                            Timber.d(ex)
                        }

                    }
                    else -> {
                        Timber.d("No Suitable Action.")
                    }
                }

            }
        }
    }
}

Also tried using the "Send via Start Activity"

Profile Settings:

Intent Action : my.prototype.app.SCAN
Intent Delivery Type: Send via StartActivity.
Intent Category: Default.
Added to Associated Apps

AndroidManifest.xml

<activity
            android:name=".activity.ScanActivity"
            android:launchMode="singleTask">
            <intent-filter>
                <action android:name="${intentAction}" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

ScanActivity.kt

override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        Timber.d("Received Intent via Activity.")
        intent?.let {
            try {
                val data = parseData(it, this)
                viewModel.processOutput(data)
            } catch (ex: Exception) {
                Timber.e(ex)
            }
        }
    }

Any help is appreciated. Thanks in advance.

UPDATE:

private fun parseData(intent: Intent, ctx: Context): ScannerOutput {
val decodedSource =
  intent.getStringExtra(ctx.getString(R.string.datawedge_intent_key_source))

val decodedData =
    intent.getStringExtra(ctx.getString(R.string.datawedge_intent_key_data))
val decodedLabelType =
intent.getStringExtra(ctx.getString(R.string.datawedge_intent_key_label_type))
    ....

}

UPDATE:

 val filter = IntentFilter()
        filter.addCategory(Intent.CATEGORY_DEFAULT)
        filter.addAction(BuildConfig.intentAction)
        registerReceiver(scanIntentReceiver, filter)
Delphi Coder
  • 1,723
  • 1
  • 14
  • 25

1 Answers1

2

Let's clarify things a bit. If you want to read RFID tags using the MC33R, then you must use Zebra RFID API3, not intents. Zebra is considering using the intents also for RFID, but at the moment the best option is to use the SDK, not the intent Broadcaster/Receiver. If you intend to use the barcode scanner, then the official (new) way of doing it is through intents. To get the intents you must configure a profile in the Data Wedge, you must activate intent broadcasing and specify the intent action in the profile, if you do so, you'll receive the intent. Look for the following settings in the data Wedge profile (default profile is good):

Intent Output = ON 
Intent action = my.prototype.app.SCAN 
Intent distribution (or delivery): Broadcast

I can assure you that these settings will work for the barcode scanner, but in case you want to use the RFID antenna, download the API3 SDK from Zebra Developer site and follow the examples.

***UPDATE

val filter = IntentFilter()
filter.addCategory(Intent.CATEGORY_DEFAULT)
filter.addAction("my.prototype.app.SCAN")//here set the action (same as in DataWedge app)
this.requireContext().registerReceiver(this, filter)

Implement

BroadcastReceiver

and add:

override fun onReceive(context: Context?, intent: Intent?) {
        //Receives readings from barcode scanner
        val action = intent!!.action

        if (action == "my.prototype.app.SCAN") {
            val decodedData = intent.getStringExtra("com.symbol.datawedge.data_string")
            

            if (decodedData != null) {
                //decodedData is your barcode
            }
        }
    }
Sergiob
  • 838
  • 1
  • 13
  • 28
  • Please check this doc : https://techdocs.zebra.com/datawedge/7-3/guide/input/rfid/ I think they've added intents for RFID as well. Thanks. – wishnuprathikantam Mar 17 '21 at 14:25
  • I didn't say they don't have it. I said it is not the best way to go (...yet). One year ago there was almost nothig. For a production app it is still too early to use the intents for RFID readings, on the contrary, intents and Brodacast Receivers is the way to go in case you want to use the barcode scanner. If you want to use intents, better to wait a little bit more in order to let Zebra consolidate the technology – Sergiob Mar 17 '21 at 15:22
  • Ok thanks, Also I've tried using regular barcodes as well but the barcode is captured as input text instead of intents any idea why is that happening? – wishnuprathikantam Mar 17 '21 at 16:20
  • I have added receiver to the manifest also using register and unregister in the activity. Also tried with onNewIntent but still no luck. – wishnuprathikantam Mar 17 '21 at 16:22
  • I've added the parse data method to my question and as per your answer I can see I am correctly registering the intent. however, Even "S1: Broadcast Scan Intent Received." is not seen logs that is placed before the if/when statement. – wishnuprathikantam Mar 17 '21 at 17:38
  • The only reason you do not receive the intent is because you didn’t properly configure the DataWedge. I don’t see any other logical reason. I’ve used it hundreds of times so far and it always worked. Post pictures or video of the whole profile so that I can take a look – Sergiob Mar 17 '21 at 21:53
  • Also, at that document link you provided (https://techdocs.zebra.com/datawedge/7-3/guide/input/rfid/) it talks about needing to map the hardware trigger to a specific action (scanning or RFID), looks like you cannot have both simultaneously. There should also be an RWDemo application preinstalled whose DataWedge profile you can copy to ensure yours is correct. – Darryn Campbell Mar 18 '21 at 07:20
  • Do not forget to restart the device. Sometimes the scanner stops working and a cold boot fixes that issue – Sergiob Mar 18 '21 at 11:27
  • receiving the following log event in RXLogger: Sending non protected broadcast my.prototype.app.SCAN from system 1598: com.symbol.datawedge/ pkg com.symbol.datawedge. – wishnuprathikantam Mar 19 '21 at 05:50
  • @DarrynCampbell I don't see any RWDemo profile but after updating the os i can see RFID settings on all available profiles. btw there is a profile named DWDEMO. What I see from the logs i think the intent is restricted for some reason. Does it require something like that? I;ve run the same app on an emulator and fired intents with adb shell and is working. – wishnuprathikantam Mar 19 '21 at 07:29
  • Also tried using sendBroadcast for soft scan and this message appears in the log "Sending non protected broadcast com.symbol.datawedge.scanner_status from system 4357: com.symbol.datawedge pkg com.symbol.datawedge" – wishnuprathikantam Mar 19 '21 at 07:36
  • https://github.com/darryncampbell/DataWedgeKotlin tried using the apk from this sample project and same message is appearing in logs. – wishnuprathikantam Mar 19 '21 at 08:11
  • Also tried with the RWDemo app and the same message is appearing in the logs And nothing is received in the app. – wishnuprathikantam Mar 21 '21 at 07:03
  • Have you tried to restart the device and check weather you haven't other apps running in the background ? Try that before anything else – Sergiob Mar 22 '21 at 08:07