I want my Xamarin Forms application to disable screenshots. Is there a way to do so? Note: I found solutions in pure Android and iOS versions, but I need Xamarin solution. If there is a way to embed pure Android and iOS solution in someway, I also accept that. Thanks :)
Is there a way to disable screenshot in Xamarin Forms?
Asked Answered
There is no 100% effective way to block user from taking screenshot/record.
You have some things you can do but none of them gives you the guarantee that the user didn't do that.
I will always need to implement this specific in Android and iOS.
Is there a way to apply them in Xamarin Forms? –
Boots
You will have to do it specifically in Android and iOS projects. –
Bevus
You can disable screenshots adding this line on MainActivity.cs (Xamarin):
protected override void OnCreate(Bundle savedInstanceState)
{
...
...
Window.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);
}
We can't stop the screenshot capture. Instead of we can make the black screen for all screenshot. Add under the AppDelegate.cs
public override UIWindow Window { get; set; }
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Window = new UIWindow(frame: UIScreen.MainScreen.Bounds);
var initialViewController = new SplashViewController();
Window.RootViewController = initialViewController;
Window.MakeKeyAndVisible();
MakeSecureWindow();
return base.FinishedLaunching(app, options);
}
public void MakeSecureWindow()
{
var field = new UITextField();
field.SecureTextEntry = true;
Window.AddSubview(field);
field.CenterYAnchor.ConstraintEqualTo(Window.CenterYAnchor).Active = true;
field.CenterXAnchor.ConstraintEqualTo(Window.CenterXAnchor).Active = true;
Window.Layer.SuperLayer?.AddSublayer(field.Layer);
field.Layer.Sublayers.LastOrDefault().AddSublayer(Window.Layer);
}
© 2022 - 2024 — McMap. All rights reserved.