我想截取应用程序屏幕(结果页面)的截图,然后在社交媒体上分享。我尝试使用https://github.com/gitawego/cordova-screenshot,但它给我一个错误https://i.stack.imgur.com/dbpvZ.png。我使用的是phonegap 3.4.0。
在您的应用程序中安装以下插件
cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git
和
cordova plugin add https://github.com/gitawego/cordova-screenshot.git
PhoneGap插件也可以通过将'cordova'替换为' PhoneGap local'来安装
安装插件后,通过执行
来准备项目$ cordova prepare
在脚本中添加以下代码:
<script>
function sharePhoto() {
var imageLink;
console.log('Calling from CapturePhoto');
navigator.screenshot.save(function(error,res){
if(error){
console.error(error);
}else{
console.log('ok',res.filePath); //should be path/to/myScreenshot.jpg
//For android
imageLink = res.filePath;
window.plugins.socialsharing.share(null, null,'file://'+imageLink, null);
//For iOS
//window.plugins.socialsharing.share(null, null,imageLink, null)
}
},'jpg',50,'myScreenShot');
}
</script>
按下键调用上述函数:
<button onclick="sharePhoto();">Share Screenshot</button>
如果您无法看到登录控制台,请安装以下插件并重新准备您的项目。
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git