mirror of
https://github.com/sdkcarlos/cordova-ourcodeworld-preventscreenshots.git
synced 2025-01-19 05:22:51 +08:00
Fix
This commit is contained in:
parent
349402e35c
commit
a64b67faa4
@ -12,17 +12,41 @@ public class OurCodeWorldpreventscreenshots extends CordovaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
|
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
|
||||||
|
final CallbackContext callbacks = callbackContext;
|
||||||
|
|
||||||
if (ACTION_ENABLE.equals(action)) {
|
if (ACTION_ENABLE.equals(action)) {
|
||||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
cordova.getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
|
try{
|
||||||
WindowManager.LayoutParams.FLAG_SECURE);
|
// 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)){
|
}else if(ACTION_DISABLE.equals(action)){
|
||||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
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*/
|
/*global cordova, module*/
|
||||||
|
(function(module){
|
||||||
|
function PreventScreenshots(){
|
||||||
|
var core = {};
|
||||||
|
var isEnabled = false;
|
||||||
|
|
||||||
module.exports = {
|
var callFunctionIfExists = function(fn,params){
|
||||||
enableScreenshots: function(){
|
if(typeof(fn) !== "function"){
|
||||||
cordova.exec(function(data){
|
return false;
|
||||||
console.info(data);
|
}
|
||||||
}, function(err){
|
|
||||||
console.error(err);
|
fn.call();
|
||||||
}, "OurCodeWorldpreventscreenshots", "enable", []);
|
return true;
|
||||||
},
|
};
|
||||||
disableScreenshots: function(){
|
|
||||||
cordova.exec(function(data){
|
core.enable = function(success,error){
|
||||||
console.info(data);
|
cordova.exec(function(data){
|
||||||
}, function(err){
|
isEnabled = true;
|
||||||
console.error(err);
|
callFunctionIfExists(success);
|
||||||
}, "OurCodeWorldpreventscreenshots", "disable", []);
|
}, 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