From a7f72973a8224ef9ec9f3680a06cb9556844c181 Mon Sep 17 00:00:00 2001 From: Aliaksei Astafyeu Date: Tue, 6 Aug 2024 16:08:09 +0200 Subject: [PATCH] one more try to fix Android discovery --- .../EscPosPrinterDiscoveryModule.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/reactnativeescposprinter/EscPosPrinterDiscoveryModule.java b/android/src/main/java/com/reactnativeescposprinter/EscPosPrinterDiscoveryModule.java index 00507fe..cac7082 100644 --- a/android/src/main/java/com/reactnativeescposprinter/EscPosPrinterDiscoveryModule.java +++ b/android/src/main/java/com/reactnativeescposprinter/EscPosPrinterDiscoveryModule.java @@ -41,22 +41,19 @@ import com.reactnativeescposprinter.EposStringHelper; -import java.util.ArrayList; - @ReactModule(name = EscPosPrinterDiscoveryModule.NAME) public class EscPosPrinterDiscoveryModule extends ReactContextBaseJavaModule implements ActivityEventListener { private Context mContext; - private ArrayList mPrinterList = null; + private WritableArray mPrinterList = null; private final ReactApplicationContext reactContext; public static final String NAME = "EscPosPrinterDiscovery"; public EscPosPrinterDiscoveryModule(ReactApplicationContext reactContext) { super(reactContext); - mPrinterList = new ArrayList(); this.reactContext = reactContext; mContext = reactContext; reactContext.addActivityEventListener(this); @@ -158,7 +155,7 @@ private void sendEvent(ReactApplicationContext reactContext, String eventName, @ @ReactMethod private void startDiscovery(final ReadableMap paramsMap, Promise promise) { FilterOption mFilterOption = getFilterOptionsFromParams(paramsMap); - mPrinterList.clear(); + mPrinterList = Arguments.createArray(); try { Discovery.start(mContext, mFilterOption, mDiscoveryListener); @@ -231,9 +228,9 @@ public synchronized void run() { printerData.putString("macAddress", deviceInfo.getMacAddress()); printerData.putString("bdAddress", deviceInfo.getBdAddress()); - mPrinterList.add(printerData); + mPrinterList.pushMap(printerData); - sendEvent(reactContext, "onDiscovery", Arguments.fromList(mPrinterList)); + sendEvent(reactContext, "onDiscovery", Arguments.fromList(mPrinterList.toArrayList())); } }); }