@herdwatch/cordova-plugin-screenshot
v0.1.8-fix.1
Published
screenshot PhoneGap Plugin for Android
Readme
cordova-screenshot
Why this fork exists
Forked from upstream because saving a screenshot needed to keep working on Android 13+ (SDK 33), where the old WRITE_EXTERNAL_STORAGE permission check no longer applies.
Published as @herdwatch/cordova-plugin-screenshot.
Changes from upstream:
- Skip the
WRITE_EXTERNAL_STORAGEpermission check on Android SDK >= 33 (src/android/Screenshot.java), since that permission is no longer granted/needed under scoped storage and the old check would otherwise block saving. - Dropped macOS/OSX platform support (removed the
osxblock fromplugin.xmland deletedsrc/osx/Screenshot.h/.m). - Republished under the
@herdwatchnpm scope, with a correctedenginesfield and plugin display name/description inplugin.xml.
The Screenshot plugin allows your application to take screenshots of the current screen and save them into the phone.
how to install
install it via cordova cli
ioinic cordova plugin add @herdwatch/cordova-plugin-screenshot
cordova plugin add @herdwatch/cordova-plugin-screenshot
cordova plugin add https://github.com/herdwatch-apps/cordova-plugin-screenshot.gitnotice: in iOS, only jpg format is supported in Android, the default WebView is supported
Ionic
npm i @awesome-cordova-plugins/screenshotusage
navigator.screenshot.save(function(error,res){
if(error){
console.error(error);
}else{
console.log('ok',res.filePath);
}
});take screenshot with jpg and custom quality
navigator.screenshot.save(function(error,res){
if(error){
console.error(error);
}else{
console.log('ok',res.filePath);
}
},'jpg',50);define a filename
navigator.screenshot.save(function(error,res){
if(error){
console.error(error);
}else{
console.log('ok',res.filePath); //should be path/to/myScreenshot.jpg
}
},'jpg',50,'myScreenShot');screenshot files are stored in /sdcard/Pictures for android.
take screenshot and get it as Data URI
navigator.screenshot.URI(function(error,res){
if(error){
console.error(error);
}else{
html = '<img style="width:50%;" src="'+res.URI+'">';
document.body.innerHTML = html;
}
},50);usage in AngularJS
.service('$cordovaScreenshot', ['$q', function ($q){
return {
capture: function (filename, extension, quality){
extension = extension || 'jpg';
quality = quality || '100';
var defer = $q.defer();
navigator.screenshot.save(function (error, res){
if (error) {
console.error(error);
defer.reject(error);
} else {
console.log('screenshot saved in: ', res.filePath);
defer.resolve(res.filePath);
}
}, extension, quality, filename);
return defer.promise;
}
};
}])Known Issue
License
this repo uses the MIT license
