0

嗨,这是我的第一篇文章,但我一直在尝试从这里使用 Screenshot 插件: https ://github.com/phonegap/phonegap-plugins/tree/88a57e1c232f604f73be5bd82868d711ac235424/Android/Screenshot

我得到这个错误:Uncaught TypeError: Cannot call method 'SaveScreenshot' of undefined at file ...而且我真的不知道为什么它给我一个错误!欢迎任何帮助

这是调用该方法的JS:

document.addEventListener("deviceready", onDeviceReady, false);
        // PhoneGap is ready
        //
     function onDeviceReady() {
        $('#saveBtn').click(function(){
            window.plugins.Screenshot.saveScreenshot();
        }); 
  }

这是按钮的 html

<button id="saveBtn">Save</button><br>

我已经获取了 Screenshot.js 文件和所有内容

编辑:如果有帮助,我正在使用 Cordova 2.0.0,并且我正在使用为同一版本的 Cordova 编码的插件 Screenshot

4

2 回答 2

1

尝试:

window.plugins.screenshot.saveScreenshot();

从源代码windows.plugins.screenshot看来都是小写字符:

if (!window.plugins.screenshot) { 
    window.plugins.screenshot = cordova.require("cordova/plugin/screenshot");
}
于 2013-05-15T16:51:26.297 回答
0

我也面临同样的问题。在这里,我正在为我解释问题的原因。转到您的插件 config.xml 并查看目录路径是否正确。

<js-module src="www/hello.js" name="hello">
<clobbers target="cordova.plugins.hello" />

<config-file target="res/xml/config.xml" parent="/*">
  <feature name="Hello">
    <param name="android-package" value="com.example.hello.Hello"/>
  </feature>
</config-file>

<source-file src="src/android/Hello.java" target-dir="src/com/example/hello"/>

具体路径。有时它会消磨我们的时间。

于 2015-10-05T09:46:49.500 回答