Screenshot.js file:
var formats = ['png','jpg'];
function Screenshot() {
}
Screenshot.prototype.save = function (callback,format,quality, filename) {
format = (format || 'png').toLowerCase();
filename = filename || 'screenshot_'+Math.round((+(new Date()) + Math.random()));
if(formats.indexOf(format) === -1){
return callback && callback(new Error('invalid format '+format));
}
quality = typeof(quality) !== 'number'?100:quality;
cordova.exec(function(res){
callback && callback(null,res);
}, function(error){
callback && callback(error);
}, "Screenshot", "saveScreenshot", [format, quality, filename]);
};
Screenshot.install = function () {
if (!window.plugins) {
window.plugins = {};
}
window.plugins.screenshot = new Screenshot();
return window.plugins.screenshot;
};
cordova.addConstructor(Screenshot.install);
This way I can make the call with the following code:
window.plugins.screenshot.save(function(error,res){
if(error){
alert(error);
}else{
alert('ok',res.filePath);
}
},'jpg',50,'myScreenShot');
This worked perfectly on my Android smartphone.
I also added res / xml / config.xml:
<feature name="Screenshot">
<param name="android-package" value="org.apache.cordova.screenshot.Screenshot"/>
</feature>
In the AndroidManifest.xml file:
And added the java class in the following package: org.apache.cordova.screenshot.Screenshot
All these configurations contain information in the plugin.xml file of the plugin.
source
share