如何在Cordova插件中设置事件侦听器

如何在Cordova插件中设置事件侦听器,cordova,titanium,appcelerator-titanium,Cordova,Titanium,Appcelerator Titanium,我想问一下如何在Cordova插件中设置自己的事件侦听器 我的Android有一个共享对话框,我想让我的Javascript为onSharedAlogDismiss或onSharedAloglasunched Javascript中可能发生的情况如下所示 // Set a listener for dialog dismiss document.addEventListener('onShareDialogDismiss', listenerCallback, false); // Set a

我想问一下如何在Cordova插件中设置自己的事件侦听器

我的Android有一个
共享对话框
,我想让我的Javascript为
onSharedAlogDismiss
onSharedAloglasunched

Javascript中可能发生的情况如下所示

// Set a listener for dialog dismiss
document.addEventListener('onShareDialogDismiss', listenerCallback, false);

// Set a listener for dialog launch
document.addEventListener('onShareDialogLaunch', launchCallback, false);
我有来自Tianium的这段代码,但它使用的是
TiViewProxy
类,可能知道如何在纯Android实现中为
fireEvent()
做一个替代方案


谢谢

首先,你已经读过了吗

然后您可以看到这样的插件是如何实现的:

例如,检查以下代码行以引发文档事件:

cordova.fireDocumentEvent("offline");

阅读cordova.js内部的内容有一个关于此API的最低文档:

/**
 * Method to fire event from native code
 * bNoDetach is required for events which cause an exception which needs to be caught in native code
 */
fireDocumentEvent: function(type, data, bNoDetach)

另一个可用的API是
FireindowEvent:function(type,data)
,但是您可以找到其他直接在cordova.js中读取的API。

网络信息插件通过使用每半秒运行一次的计时器来检查状态是否已更改,从而实现了一个相当麻烦的“事件”。应该有一种更智能的方法来触发事件而不使用Javascript计时器,事实上这是一种“欺骗”方法,而不是真正的事件触发机制。应该使用类似于BroadcastReceiver(在ConnectionManager.CONNECTIVITY_操作上带有筛选器)的东西。
/**
 * Method to fire event from native code
 * bNoDetach is required for events which cause an exception which needs to be caught in native code
 */
fireDocumentEvent: function(type, data, bNoDetach)