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())); } }); }