Cordova plugin callback received after the second plugin call

I created a cordova plugin (3.3.0) that launches an action and waits for a result. But the callback (simple alert) is not a call until the second plugin is enabled. Here is the code:

public boolean execute(String action, final JSONArray args, final CallbackContext cbc) throws JSONException { this.callbackContext = cbc; try { Intent i = new Intent(cordova.getActivity(), ActivityCamera.class); this.cordova.setActivityResultCallback(PhotoMokoPlugin.this); this.cordova.startActivityForResult(PhotoMokoPlugin.this, i, 0); PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); return true; } catch (JSONException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); return false; } } @Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); try { callbackContext.success(json.toString()); // Doesn't matter if success or error } catch (JSONException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); } } 

Only ActivityCamera setResult with new Intent avec finish() ;

For example: if I click the button that calls the plugin, nothing happens. I click a second time, a warning message appears and nothing else (usually another warning) ...

Do you have any ideas?

Tell me if more code is needed.

EDIT: Updating Cordoba did not solve the problem.

EDIT 2: The problem seems to come from this code:

 @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } } 

If I delete it, the call will be called for the first time. Is there a problem?

0
source share
3 answers

In this situation, I also had problems.

In my case, the plugin is launched from the tag in which the click handler is attached in the contents of the iframe. When I moved the tag and click handler to the parent document, the problems are resolved.

Can you try these?

+1
source

I fixed this problem for me, wish it worked for others. I use require.js, the problem arose when I called the requirement ("cord") more than once in my code, after I removed the redundancy, the problem will disappear.

0
source

For me, the problem was simply having an empty iframe tag in the HTML document. Removing the iframe completely fixed the problem. Thanks 장지윤 for pointing me in the right direction.

0
source

Source: https://habr.com/ru/post/969677/


All Articles