简体   繁体   English

Android - 如何使用PhoneGap Share插件

[英]Android - How to use the PhoneGap Share plugin

I am trying to use the PhoneGap Share plugin which is supposed to bring up the native Android "Share" window which allows the user to pick which application to share to. 我正在尝试使用PhoneGap Share插件,该插件应该调出原生的Android“Share”窗口,允许用户选择要共享的应用程序。

https://github.com/phonegap/phonegap-plugins/tree/master/Android/Share https://github.com/phonegap/phonegap-plugins/tree/master/Android/Share

I have a hyperlink which calls the following code (provided on github). 我有一个超链接,调用以下代码(在github上提供)。

window.plugins.share.show({
    subject: 'I like turtles',
    text: 'http://www.mndaily.com'
},

function () {}, // Success function
function () {
    alert('Share failed')
} // Failure function);

When trying to debug the app on my phone, I get the following error: 尝试在手机上调试应用程序时,出现以下错误:

Cannot call method 'show' of undefined at file:///android_asset/www/index.html 无法在file:///android_asset/www/index.html调用undefined方法'show'

What do I need to do to get this to work? 我需要做些什么才能让它发挥作用?

I have faced the same problem today. 我今天遇到了同样的问题。 I made it work using the following code instead of the window.plugins thing: 我使用以下代码而不是window.plugins的东西使它工作:

var share = new Share();
share.show({
    subject: 'I like turtles',
    text: 'http://www.mndaily.com'},
    function() {}, // Success function
    function() {alert('Share failed')} // Failure function

);

This is what you can do... 这就是你能做的......

  • Add to plugins.xml : 添加到plugins.xml

     <plugin name="Share" value="com.schaul.plugins.share.Share"/ > 
  • Save share.js to \\assets\\www\\ share.js保存到\\assets\\www\\

  • From index.html , call 来自index.html ,请致电

     <script type="text/javascript" charset="utf-8" src="share.js" ></script> 
  • Add Share.java to \\src\\com.schaul.plugins.share Share.java添加到\\src\\com.schaul.plugins.share
    that is: src\\com\\schaul\\plugins\\share\\Share.java 即:src \\ com \\ schaul \\ plugins \\ share \\ Share.java

  • In index.html , call the following code after the phonegap.1.2.0.js and share.js files are loaded: index.html ,在加载phonegap.1.2.0.js和share.js文件后调用以下代码:

Call the code that Petroy mentioned... 调用Petroy提到的代码......

var share = new Share();
share.show({
    subject: 'I like turtles',
    text: 'http://www.mndaily.com'},
    function() {}, // Success function
    function() {alert('Share failed')} // Failure function

);

Let us know it works... 让我们知道它有效......

The error tells you that the object window.plugins does not have a "share property". 该错误告诉您对象window.plugins没有“共享属性”。

Check that you followed the installation steps of the share plugin, and that you added the loading of the share.js file in your index.html, something the installation steps omits to tell you. 检查您是否遵循了共享插件的安装步骤 ,并在index.html中添加了share.js文件的加载,安装步骤省略了这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM