Skip to content

Commit

Permalink
one more try to fix Android discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
tr3v3r committed Aug 6, 2024
1 parent ec86a74 commit a7f7297
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<WritableMap> 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<WritableMap>();
this.reactContext = reactContext;
mContext = reactContext;
reactContext.addActivityEventListener(this);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()));
}
});
}
Expand Down

0 comments on commit a7f7297

Please sign in to comment.