[英]Android - How to use the PhoneGap Share plugin
我正在嘗試使用PhoneGap Share插件,該插件應該調出原生的Android“Share”窗口,允許用戶選擇要共享的應用程序。
https://github.com/phonegap/phonegap-plugins/tree/master/Android/Share
我有一個超鏈接,調用以下代碼(在github上提供)。
window.plugins.share.show({
subject: 'I like turtles',
text: 'http://www.mndaily.com'
},
function () {}, // Success function
function () {
alert('Share failed')
} // Failure function);
嘗試在手機上調試應用程序時,出現以下錯誤:
無法在file:///android_asset/www/index.html調用undefined方法'show'
我需要做些什么才能讓它發揮作用?
我今天遇到了同樣的問題。 我使用以下代碼而不是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
);
這就是你能做的......
添加到plugins.xml
:
<plugin name="Share" value="com.schaul.plugins.share.Share"/ >
將share.js
保存到\\assets\\www\\
來自index.html
,請致電
<script type="text/javascript" charset="utf-8" src="share.js" ></script>
將Share.java
添加到\\src\\com.schaul.plugins.share
即:src \\ com \\ schaul \\ plugins \\ share \\ Share.java
在index.html
,在加載phonegap.1.2.0.js和share.js文件后調用以下代碼:
調用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
);
讓我們知道它有效......
使用cordova 2.7及更高版本的更新版本
https://github.com/robincharummoottil/phonegap-plugins/tree/master/Android/Share
該錯誤告訴您對象window.plugins沒有“共享屬性”。
檢查您是否遵循了共享插件的安裝步驟 ,並在index.html中添加了share.js文件的加載,安裝步驟省略了這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.