This commit is contained in:
Carlos Delgado 2016-06-09 16:36:44 +02:00
parent 349402e35c
commit a64b67faa4
2 changed files with 67 additions and 18 deletions

View File

@ -12,17 +12,41 @@ public class OurCodeWorldpreventscreenshots extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
final CallbackContext callbacks = callbackContext;
if (ACTION_ENABLE.equals(action)) {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
cordova.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
try{
// Allow to make screenshots removing the FLAG_SECURE
cordova.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
PluginResult result = new PluginResult(PluginResult.Status.OK, "");
result.setKeepCallback(true);
callbacks.sendPluginResult(result);
}catch(Exception e){
PluginResult result = new PluginResult(PluginResult.Status.ERROR, "");
result.setKeepCallback(true);
callbacks.sendPluginResult(result);
}
}
});
}else if(ACTION_DISABLE.equals(action)){
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
cordova.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
try{
// Disable the creation of screenshots adding the FLAG_SECURE to the window
cordova.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
PluginResult result = new PluginResult(PluginResult.Status.OK, "");
result.setKeepCallback(true);
callbacks.sendPluginResult(result);
}catch(Exception e){
PluginResult result = new PluginResult(PluginResult.Status.ERROR, "");
result.setKeepCallback(true);
callbacks.sendPluginResult(result);
}
}
});
}

View File

@ -1,18 +1,43 @@
/*global cordova, module*/
(function(module){
function PreventScreenshots(){
var core = {};
var isEnabled = false;
module.exports = {
enableScreenshots: function(){
cordova.exec(function(data){
console.info(data);
}, function(err){
console.error(err);
}, "OurCodeWorldpreventscreenshots", "enable", []);
},
disableScreenshots: function(){
cordova.exec(function(data){
console.info(data);
}, function(err){
console.error(err);
}, "OurCodeWorldpreventscreenshots", "disable", []);
var callFunctionIfExists = function(fn,params){
if(typeof(fn) !== "function"){
return false;
}
fn.call();
return true;
};
core.enable = function(success,error){
cordova.exec(function(data){
isEnabled = true;
callFunctionIfExists(success);
}, function(err){
callFunctionIfExists(error);
}, "OurCodeWorldpreventscreenshots", "enable", []);
};
core.disable = function(success,error){
cordova.exec(function(data){
isEnabled = false;
callFunctionIfExists(success);
}, function(err){
callFunctionIfExists(error);
}, "OurCodeWorldpreventscreenshots", "disable", []);
};
core.isEnabled = function(){
return isEnabled;
};
return core;
}
};
module.exports = new PreventScreenshots();
})(module);