Cordova插件回调在第二个插件调用后收到 [英] Cordova plugin callback received after second plugin call
问题描述
我创建了一个cordova插件(3.3.0),它启动一个活动并等待结果。但回调(简单的警报)不会调用,直到lauch插件第二次。这是代码:
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()); //如果成功或错误不重要
}
catch(JSONException e)
{
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
}
}
仅限ActivityCamera setResult
与新的意图
avec finish()
;
例如:如果我点击一个调用插件的按钮,什么也没有发生。我再次点击,显示提醒消息,没有什么(通常是另一个提醒)...
你有什么想法吗?
告诉我是否需要更多代码。
编辑:更新Cordova没有解决问题。 / p>
编辑2:问题似乎来自此代码:
@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);
}
}
如果我删除它,回调被称为第一个时间。是否有问题?
我在这种情况下也遇到了麻烦。
在我的例子中,插件是从iframe内容中绑定点击处理程序的标签触发的。
当我将一个标签和点击处理程序移动到父文档时,问题就解决了。
你可以试试这样吗?
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 ?
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?
这篇关于Cordova插件回调在第二个插件调用后收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!