Is there a way to disable screenshot in Xamarin Forms?
Asked Answered
L

3

3

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 :)

Lawtun answered 22/6, 2016 at 6:33 Comment(0)
B
5

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.

See this and this for android. See this and this for iOs

Bevus answered 22/6, 2016 at 7:34 Comment(2)
Is there a way to apply them in Xamarin Forms?Boots
You will have to do it specifically in Android and iOS projects.Bevus
A
0

You can disable screenshots adding this line on MainActivity.cs (Xamarin):

protected override void OnCreate(Bundle savedInstanceState)
{
   ...
   ...
   Window.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);
}
Addam answered 13/11, 2020 at 1:14 Comment(0)
G
0

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);
        }
Gerous answered 21/2 at 13:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.