如何在 Cordova 插件中设置事件监听器
How to set event listeners in Cordova plugin
我想问一下如何在 Cordova 插件中设置自己的事件侦听器。
我的 Android 有这个 Share dialog
,我想让我的 Javascript 为 onShareDialogDismiss
或 onShareDialogLaunched
[=16 设置监听器=]
在 Javascript 中可能发生的事情看起来像这样。
// Set a listener for dialog dismiss
document.addEventListener('onShareDialogDismiss', listenerCallback, false);
// Set a listener for dialog launch
document.addEventListener('onShareDialogLaunch', launchCallback, false);
我有来自 Titanium 的这段代码,但它使用的是 TiViewProxy
class,可能会知道如何在纯 Android 实现中为 fireEvent()
做一个替代方案
谢谢!
首先你读过Cordova plugin development documentation了吗?
然后你可以看到像这样的插件cordova-plugin-network-information是如何完成的:
例如检查 JS interface code 中有这些代码行来引发 Document 事件:
cordova.fireDocumentEvent("offline");
或
cordova.fireDocumentEvent("online");
阅读内部 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 是 fireWindowEvent: function(type, data)
,但您可以直接在 cordova.js.
中找到其他 API 阅读
我想问一下如何在 Cordova 插件中设置自己的事件侦听器。
我的 Android 有这个 Share dialog
,我想让我的 Javascript 为 onShareDialogDismiss
或 onShareDialogLaunched
[=16 设置监听器=]
在 Javascript 中可能发生的事情看起来像这样。
// Set a listener for dialog dismiss
document.addEventListener('onShareDialogDismiss', listenerCallback, false);
// Set a listener for dialog launch
document.addEventListener('onShareDialogLaunch', launchCallback, false);
我有来自 Titanium 的这段代码,但它使用的是 TiViewProxy
class,可能会知道如何在纯 Android 实现中为 fireEvent()
做一个替代方案
谢谢!
首先你读过Cordova plugin development documentation了吗?
然后你可以看到像这样的插件cordova-plugin-network-information是如何完成的:
例如检查 JS interface code 中有这些代码行来引发 Document 事件:
cordova.fireDocumentEvent("offline");
或
cordova.fireDocumentEvent("online");
阅读内部 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 是 fireWindowEvent: function(type, data)
,但您可以直接在 cordova.js.