diff --git a/android/src/main/java/com/reactnativeescposprinter/EscPosPrinterDiscoveryModule.java b/android/src/main/java/com/reactnativeescposprinter/EscPosPrinterDiscoveryModule.java index 9812ece..00507fe 100644 --- a/android/src/main/java/com/reactnativeescposprinter/EscPosPrinterDiscoveryModule.java +++ b/android/src/main/java/com/reactnativeescposprinter/EscPosPrinterDiscoveryModule.java @@ -41,19 +41,22 @@ import com.reactnativeescposprinter.EposStringHelper; +import java.util.ArrayList; + @ReactModule(name = EscPosPrinterDiscoveryModule.NAME) public class EscPosPrinterDiscoveryModule extends ReactContextBaseJavaModule implements ActivityEventListener { private Context mContext; - private WritableArray mPrinterList = null; + private ArrayList 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); @@ -155,7 +158,7 @@ private void sendEvent(ReactApplicationContext reactContext, String eventName, @ @ReactMethod private void startDiscovery(final ReadableMap paramsMap, Promise promise) { FilterOption mFilterOption = getFilterOptionsFromParams(paramsMap); - mPrinterList = Arguments.createArray(); + mPrinterList.clear(); try { Discovery.start(mContext, mFilterOption, mDiscoveryListener); @@ -228,9 +231,9 @@ public synchronized void run() { printerData.putString("macAddress", deviceInfo.getMacAddress()); printerData.putString("bdAddress", deviceInfo.getBdAddress()); - mPrinterList.pushMap(printerData); + mPrinterList.add(printerData); - sendEvent(reactContext, "onDiscovery", mPrinterList); + sendEvent(reactContext, "onDiscovery", Arguments.fromList(mPrinterList)); } }); }