No onData/onStatus when writing a Module for React Native

I'm following the Basic Tutorial but don't get any data feedback at all. What am I doing wrong?

 

I tried a lot of test projects and ways but can't get it to work. This is the most basic test from react-native for writing a module and the test from your documentation for basic scanning. Also, calling AsyncTask kills and reloads react-native. So dunno what to do about that. Can probably just run them in this thread.

 

package com.somescanner.SHEScanner;   import android.app.AlertDialog; import android.content.DialogInterface; import android.widget.Toast;   import com.symbol.emdk.EMDKManager; import com.symbol.emdk.EMDKManager.EMDKListener; import com.symbol.emdk.EMDKResults; import com.symbol.emdk.barcode.BarcodeManager; import com.symbol.emdk.barcode.ScanDataCollection; import com.symbol.emdk.barcode.Scanner; import com.symbol.emdk.barcode.Scanner.DataListener; import com.symbol.emdk.barcode.Scanner.StatusListener; import com.symbol.emdk.barcode.ScannerException; import com.symbol.emdk.barcode.ScannerResults; import com.symbol.emdk.barcode.StatusData;   import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod;   import java.util.ArrayList; import java.util.Map; import java.util.HashMap;   public class SHEScannerModule extends ReactContextBaseJavaModule implements EMDKListener, StatusListener, DataListener {       private EMDKManager emdkManager = null;     private BarcodeManager barcodeManager = null;     private Scanner scanner = null;       private static final String DURATION_SHORT_KEY = "SHORT";     private static final String DURATION_LONG_KEY = "LONG";       public SHEScannerModule(ReactApplicationContext reactContext) {         super(reactContext);     }       @Override     public String getName() {         return "ToastExample";     }       @Override     public void initialize() {         Toast.makeText(getReactApplicationContext(), "initialize", Toast.LENGTH_SHORT).show();         EMDKResults results = EMDKManager.getEMDKManager(                 getReactApplicationContext(), this);     }       @Override     public Map<String, Object> getConstants() {         final Map<String, Object> constants = new HashMap<>();         constants.put(DURATION_SHORT_KEY, Toast.LENGTH_SHORT);         constants.put(DURATION_LONG_KEY, Toast.LENGTH_LONG);         return constants;     }       @ReactMethod     public void show(String message, int duration) {         Toast.makeText(getReactApplicationContext(), message, duration).show();     }       @Override     public void onClosed() {         // TODO Auto-generated method stub     }       @Override     public void onOpened(EMDKManager emdkManager) {         this.emdkManager = emdkManager;           try {             // Call this method to enable Scanner and its listeners             initializeScanner();         } catch (ScannerException e) {             e.printStackTrace();         }           // Toast to indicate that the user can now start scanning         Toast.makeText(getReactApplicationContext(),                 "Press Hard Scan Button to start scanning...",                 Toast.LENGTH_SHORT).show();     }       @Override     public void onData(ScanDataCollection scanDataCollection) {         Toast.makeText(getReactApplicationContext(), "Got Data", Toast.LENGTH_SHORT).show();     }       @Override     public void onStatus(StatusData statusData) {         Toast.makeText(getReactApplicationContext(), "onStatus", Toast.LENGTH_SHORT).show();     }       // Method to initialize and enable Scanner and its listeners     private void initializeScanner() throws ScannerException {         if (scanner == null) {             // Get the Barcode Manager object             barcodeManager = (BarcodeManager) this.emdkManager                     .getInstance(EMDKManager.FEATURE_TYPE.BARCODE);             // Get default scanner defined on the device             scanner = barcodeManager.getDevice(BarcodeManager.DeviceIdentifier.DEFAULT);             // Add data and status listeners             scanner.addDataListener(this);             scanner.addStatusListener(this);             // Hard trigger. When this mode is set, the user has to manually             // press the trigger on the device after issuing the read call.             scanner.triggerType = Scanner.TriggerType.HARD;             // Enable the scanner             scanner.enable();             // Starts an asynchronous Scan. The method will not turn ON the             // scanner. It will, however, put the scanner in a state in which             // the scanner can be turned ON either by pressing a hardware             // trigger or can be turned ON automatically.             scanner.read();         }     } }

Anonymous (not verified)
Is onOpened() ever getting

Is onOpened() ever getting called?  I suspect the lack of EMDKManager.getEMDKManager(...) is causing the issue: samples-emdkforandroid-6_6/MainActivity.java at BarcodeSample1 · Zebra/samples-emdkforandroid-6_6 · GitHub 

I have not used the Barcode API with ReactNative myself but I don't see why it shouldn't work as long as the EMDK library is referenced (which it must be or you'd get build errors) and you are running on a Zebra device.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Stanislav Izotov
Yeah, I get the toast for

Yeah, I get the toast for both onOpened and the end of initializeScanner(), it reads once and then stops working as I don't get any response from DataListener/StatusListener and can restart it.

And yeah, running on a Zebra device and got it to work without build errors after too many hours of trial and error!

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
You should really wait and

You should really wait and only call scanner.read() when the scanner is in the IDLE state, but if you are never getting the onStatus callback then that would be difficult.  I don't know, maybe it is something about being within a React native app that is causing it to fail.  Have you considered using DataWedge rather than the full EMDK API?  I know DataWedge works with React Native because I wrote my own module for it last year (http://www.darryncampbell.co.uk/tag/react-native/ ) bear in mind that's my personal blog however and not endorsed or supported by Zebra.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Stanislav Izotov
Yeah, I actually tried that,

Yeah, I actually tried that, I got it to work but it would reload the JS every time it got a successful scan and I couldn't solve that.

I'm messing with getReactApplicationContext now but there is no headway that it will help.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Stanislav Izotov
Nothing, tried your module

Nothing, tried your module some more with a more basic project and even your example but couldn't get it to build even after fixing most of the errors. Maybe the listeners reports to the wrong activity or something. But I don't know how they work really without source. Looking at rewriting the app in Java but that would take a couple of weeks.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Very strange, I'm not sure

Very strange, I'm not sure why the demo app with DataWedge reloaded JS every time.  I tried it this morning (https://github.com/darryncampbell/react-native-datawedge-intents) and it seemed to scan barcodes without realoading.  Since that demo app uses Datawedge, the rest of the project cannot try to instantiate the EMDK Barcode API since the latter will take priority.

I also took a look at the source code for the listeners, I can't post it here but I couldn't see anything that could be causing strangeness with React Native so no clues there I'm afraid.

End of the day, I don't think there are enough eyes on this and there is no expertise within Zebra for React-Native support - the reason for this is because the platform is not officially supported by us.  In the coming days there will be a survey posted on this portal asking for feedback on our developer tools and that would be a great forum to have your voice heard for React Native support (I'm sure you're not the only developer who would like it on our devices!)

In the short term however, if DataWedge is not an option for you and the original issue in this post cannot be resolved then I'm afraid I do not have a solution.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Stanislav Izotov
I finally solved the

I finally solved the DataWedge issue. It was configured for keyboard too and that was messing with the app probably. I'll maybe much around with the code some more later but for now DataWedge is going to be fine! Thanks for all the help!

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Miguel Tec
Hi Stanislav i'll create an

Hi Stanislav i'll create an APP in Android for an project in my job, i'm using React-native and i don't know how do integrate it. Your resource were publicated on gitHub or other service. Sorry for my bad english

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments