datalogic / android-samples-astudio

Sample apps for Datalogic Android SDK
9 stars 39 forks source link

Read listener react native #5

Closed gergobalogh closed 3 years ago

gergobalogh commented 5 years ago

I've downloaded the android-samples-astudio and managed to install/run it, scan barcodes with the skorpio x4 and display them in EditText. I can't manage to get the value through to react-native. When there is no EditText as it is in the example app, the execution doesn't even enter in the TRY part :

    try {

        // Create an anonymous class.
        listener = new ReadListener() {
// Implement the callback method. @Override public void onRead(DecodeResult decodeResult) { // Change the displayed text to the current received result. mBarcodeText.setText(decodeResult.getText()); } }; // Remember to add it, as a listener. decoder.addReadListener(listener); } catch (DecodeException e) { Log.e(LOGTAG, "Error while trying to bind a listener to BarcodeManager", e); } } Please help!!
crobinson42 commented 4 years ago

You need to send an event to the JS thread - you can read about this in the react-native docs.

Something like this:

private void emitJSEvent(String eventName, String message) {
        wrapperContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(eventName, message);
    }
gergo-balogh commented 4 years ago

Thanks. I figured it out and did it as you suggested. If anybody else hits this problem feel free to PM me. getReactApplicationContext() .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(key, payload);

codybrookshear commented 3 years ago

Hi @gergo-balogh and @crobinson42, Just wanted to let you know that we have an official react native module available now (in alpha state). It's available here:

Datalogic React Native documentation