Skip to content

Commit

Permalink
fix: set keep callback on callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
diogoqueiros committed Jan 11, 2021
1 parent 21ce138 commit a3a6705
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/android/PointMobile.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.LOG;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -39,7 +40,9 @@ public void onReceive(Context context, Intent intent) {

if (callbackContext != null) {
if (mDecodeResult.symName.equals("READ_FAIL")) {
callbackContext.error("READ_FAIL");
PluginResult result = new PluginResult(PluginResult.Status.ERROR, "READ_FAIL");
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
} else {
JSONObject json = new JSONObject();

Expand All @@ -50,12 +53,16 @@ public void onReceive(Context context, Intent intent) {
LOG.d("PointMobile", "Error sending point mobile receiver: " + e.getMessage(), e);
}

callbackContext.success(json);
PluginResult result = new PluginResult(PluginResult.Status.OK, json);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
}
}
} else {
if (callbackContext != null) {
callbackContext.error("SCANNER_ERROR");
PluginResult result = new PluginResult(PluginResult.Status.ERROR, "SCANNER_ERROR");
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
}
}
}
Expand Down Expand Up @@ -93,7 +100,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
this.onDestroy();

if (this.callbackContext != null) {
this.callbackContext.error("USER_CANCEL");
PluginResult result = new PluginResult(PluginResult.Status.ERROR, "USER_CANCEL");
result.setKeepCallback(true);
this.callbackContext.sendPluginResult(result);
this.callbackContext = null;
}

Expand Down

0 comments on commit a3a6705

Please sign in to comment.