0

I've created a cordova plugin (3.3.0), which launch an activity and waits for a result. But the callback (simple alert) isn't call until a lauch the plugin a second time. 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));
    }
}

The ActivityCamera only setResult with a new Intent avec finish();

For example : If I click on a button which call the plugin, nothing happens. I click a second time, the alert message is displayed and nothing more (normally another alert)...

Do you have any idea ?

Tell me if more code is needed.

EDIT : Updating Cordova didn't solved 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 remove it, the callback is called the first time. Is there an issue ?

thomas-hiron
  • 928
  • 4
  • 21
  • 40

3 Answers3

1

I was in trouble in this situation also.

In my case, plugin is triggered from a tag, in which click handler is bound, in iframe content. When I moved a tag and click handler to parent document, problems are solved.

Can you try like these?

장지윤
  • 31
  • 1
  • 3
  • UPDATE : Problem is not related to the position of a tag and hander. I used iframe and cordova.js is included in parent and iframe both. That was terrible mistake. I removed cordova.js from iframe and every things fine. – 장지윤 Jul 01 '14 at 10:49
  • For me, the problem seemed to come from immersive mode :/ – thomas-hiron Jul 02 '14 at 12:02
0

I fixed this problem for me, wish it work for others. I'm using require.js, the problem appeared when I was calling require("cordova") more than once in my code, after I removed redundant requires the problem disappears.

Imskull
  • 1,316
  • 14
  • 16
0

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

peter_drualas
  • 96
  • 1
  • 4