1

Please don't mark question as duplicate.cuz FLAG_SECURE don't works for me.
As here someone had recommended to use setScreenCaptureDisabled,
But he didn't added any example and also I use xamarin.
So how do I use setScreenCaptureDisabled for disabling screen recording in xamarin ?
I need working code example for xamarin c#.

Sorry IwontTell
  • 302
  • 7
  • 20
  • Hi, I have checked in local site refer to [this document](https://developer.android.com/reference/android/app/admin/DevicePolicyManager), however can not make it works in Xamarin Android. It needs to apply for system administrator permissions, and from official document can not find the key about `setScreenCaptureDisabled` in [uses-policies](https://developer.android.com/reference/android/app/admin/DeviceAdminReceiver). Later if good news will update here. – Junior Jiang Aug 24 '20 at 09:15
  • @JuniorJiang-MSFT Glad someone have seen and working on it. :) – Sorry IwontTell Aug 24 '20 at 09:18
  • `setScreenCaptureDisabled` can only be used by a device or profile owner. these are APIs designed for MDM provider, not really for applications. A device owner can only be installed on a freshly wiped device, Google has a [profile owner sample](https://github.com/android/enterprise-samples/tree/master/BasicManagedProfile) – bwt Aug 27 '20 at 09:48
  • Okay any advice or suggestion ? I just want to secure content. – Sorry IwontTell Aug 27 '20 at 10:05
  • @SorryIwontTell did you find any solution regarding this? i'm also struggling for the same problem it has become headache? – Muhammad Adeel Shoukat Nov 11 '20 at 16:26
  • Nahi, main kuch khalti ker raha tha, jis waja se flag secure work nahi ker raha tha. Ap es ko use kero bhai: https://stackoverflow.com/a/54193681/11390822 – Sorry IwontTell Nov 11 '20 at 16:31

2 Answers2

1

This is not possible in Android. You cannot prevent screen capture on a device that is not managed through a MDM provider. There is no DRM solution available to prevent screen capture for consumer Apps. The idea is that you are supposed to provide tools and features to your users, not prevent them from doing something.

The only thing you can do is to set the FLAG_SECURE on the window to prevent it to show up when screen sharing or in screenshots.

This really has nothing to do with Xamarin, but rather, simply how Android works.

Cheesebaron
  • 21,926
  • 13
  • 60
  • 110
0

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

protected override void OnCreate(Bundle savedInstanceState)
{
   ...
   ...
   Window.SetFlags(WindowManagerFlags.Secure, WindowManagerFlags.Secure);
}
AlejandroAlis
  • 161
  • 2
  • 9