【问题标题】:window.plugins undefined when trying to use the phonegap plugins on android尝试在android上使用phonegap插件时未定义window.plugins
【发布时间】:2011-10-18 01:18:33
【问题描述】:

我无法在 android 中加载插件。我已将插件添加到 plugins.xml 列表中,并在我的项目中添加了 java 代码。但是当我打电话给window.plugins 时,我仍然得到未定义的对象。为什么会这样?顺便说一句,我正在尝试使用共享插件 - https://github.com/phonegap/phonegap-plugins/tree/master/Android/Share

为了清楚起见,我添加了 phonegap.js 文件和包含 JS 插件代码的 share.js 文件。我还使用了具有相同代码的 iphone 的 EmailComposer 插件,它适用于 iphone,即在 iphone 上,它不是未定义的 window.plugins 对象。

【问题讨论】:

  • 我使用的是 phonegap 1.0.0 而不是 1.1.0,所以代码是正确的。问题是当我从 xcode 中的 iphone 版本复制其他 JavaScript 代码时,我也复制了 phonegap.js 文件。所以我有 iphone 的 phonegap.js 文件,而不是 android 的 phonegap.js 文件。愚蠢的错误,但老实说,我不认为这两个文件是不同的。

标签: android plugins cordova


【解决方案1】:

我注意到后修复了完全相同的问题...我忘记在我的 html 中引用 phonegap-1.1.0.js。我还不得不取消注释 PhoneGap.addPlugin('share', new Share());在 share.js 中。

【讨论】:

  • 这是问题的另一部分。
【解决方案2】:

我遇到了同样的问题,我想我发现了 phonegap 的问题。
你应该去看看这个线程,它可以解释为什么你不能访问你的插件:Phonegap background geolocation plugin not found

【讨论】:

    【解决方案3】:

    在 phonegap 1.1.0 中,我们无法调用 windows.plugin,而不是在您的 share.js 中调用

    PhoneGap.addConstructor(function() {
    
    });
    

    添加navigator.your plugins.js=new WebIntent();(Java 文件)并在您的javascript 中将插件称为navigator.your javascript plugin name

    【讨论】:

    • hai 我在 android 中使用带有 phonegap 1.0.0.js 的 webintent 插件,但没有使用 share.js。我收到错误 'window.plugins.webintent' [undefined] is not an文件中的对象。请指导我。提前致谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 2018-08-05
    相关资源
    最近更新 更多