如何使用Firebasemessaging的Flutter MethodChannel。

发布于 2025-01-24 22:01:50 字数 644 浏览 0 评论 0原文

我正在使用 firebase_messaging inbackgroundMessage预期的。现在,我想从此处理程序中调用平台方法,但我无法做到这一点。 MethodChannel>在此刻。我能够通过在此处创建自定义的幻影插件并实现方法通道来解决我的问题,但这有一些问题:

  • 必须管理单独的插件代码 - 不必要的样板和努力
  • 在主机应用程序代码和插件代码之间进行通信(例如,想要使用某些方法这是在主机应用程序中的平台侧实现的)。

因此,问题是:如果没有插件,是否可以实现同一件事(例如,创建MethodChannel并在全球范围内注册)。如果插件有可能,则也应该进行主应用程序。目前,如果这使事情变得更容易,我只需要覆盖Android。

I'm using firebase_messaging onBackgroundMessage handler for listening push messages and it works as expected. Now I want to call platform method from this handler, but I'm unable to do this. MethodChannel can only be registered to Android Activity, but there is no Activity at this point. I was able solve my problem by creating custom Flutter plugin and implementing MethodChannel there, but this has some problems:

  • Have to manage separate plugin code - unnecessary boilerplate and effort
  • Hard to communicate between host application code and plugin code (e.g. wanting to use some method that is implemented on platform side in host application).

So the question is: is it possible to achieve same thing without plugin (e.g. create MethodChannel and register it globally). If it is possible for plugins, it should be possible for main application as well. Currently I only need to cover Android, if this makes things easier.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文