如何从Android Cordova插件调用另一个Cordova插件? [英] How to call another cordova plugin from an android cordova plugin?

查看:294
本文介绍了如何从Android Cordova插件调用另一个Cordova插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android中调用另一个Cordova插件的最佳方法是什么?

What would be the best way to call another cordova plugin in android?

我想要一个后台服务,该服务调用服务器以获取某些信息,并且基于该信息,我需要例如设置徽章.

I want to have a background service that calls a server for some information and based on that information, I need to do for example set a badge.

我找到了Cordova后台服务插件 https://github.com/phpsa/cbsp 可以很好地实现我的目的,并与 https://github.com/katzer/cordova一起使用-plugin-badge 等.

I found a Cordova Background Services Plugin, https://github.com/phpsa/cbsp that could work well for my purposes and the use it with https://github.com/katzer/cordova-plugin-badge among others.

我想知道什么是最好的方法?我可以只包含这些类并直接从我的Java代码中对其进行调用吗?还是有其他要求?

I'm wondering what would be the best way to do it? Can I just include the classes and call them straight from my java code or is there something else that is required?

正在寻找最佳方法的指导.

Looking for guidance on best approach.

因此,显然这不是一个真正的选择.我设法在我的Java代码中包含了另一个插件,并且能够调用它,但是遇到了CallbackContext的问题,后者是Cordova平台从javascript调用插件时创建的.这基本上是徽章插件的设计功能

So apparently this isn't really a option. I managed to include the other plugin in my java code and I was able to call it, but ran into issues with CallbackContext, which is created by cordova platform when calling a plugin from javascript. This was basically a design feature of the badge plugin

我发现实现所需功能的唯一方法是从另一个插件中获取代码,并将其重构到我的后台服务中.

The only way I found to implement the features I needed was to take the code from the other plugin and refactor it into my background service.

推荐答案

例如:
public class OtherPlugin extends CordovaPlugin{ @Override protected void pluginInitialize() { YourClassPlugin yourClassPlugin = (YourClassPlugin)this.webView.getPluginManager().getPlugin("YourClassPlugin"); } }

For example:
public class OtherPlugin extends CordovaPlugin{ @Override protected void pluginInitialize() { YourClassPlugin yourClassPlugin = (YourClassPlugin)this.webView.getPluginManager().getPlugin("YourClassPlugin"); } }

这篇关于如何从Android Cordova插件调用另一个Cordova插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆