mirror of
https://github.com/sdkcarlos/cordova-ourcodeworld-preventscreenshots.git
synced 2025-01-18 13:02:50 +08:00
Fix
This commit is contained in:
parent
349402e35c
commit
a64b67faa4
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user