skip to Main Content

I want to protect an app against any kind of recordings possible, may it be screenshots or screen-recordings. I know I can use the library flutter_windowmanager to set a flag preventing screenshots and making the screen-recordings show a black screen, but audio can still be captured anyway, and I want to prevent this to.

Is there any way to do this? Preventing screen-recordings or recording nothing at all both are good enough solutions.

I have tried using several options, for example the libraries audio_session and screen_capture_event, and the class WidgetsBindingObserver, all without success.

2

Answers


  1. For Android:

    1. Locate your MainActivity class inside the embedded android project directory in your Flutter project.
    2. Add the following import to your main activity class:
    import android.view.WindowManager.LayoutParams; 
    
    1. Add the following line to your MainActivity’s onCreate method:
    getWindow().addFlags(LayoutParams.FLAG_SECURE);
    

    For Example :

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      
      getWindow().addFlags(LayoutParams.FLAG_SECURE); 
      
    }
    

    For iOS:

    1. Locate your AppDelegate.m class inside the embedded ios project
      directory in your Flutter project.
    2. Add given below snippet to your AppDelegate.m class file
    - (void)applicationWillResignActive:(UIApplication *)application{
        self.window.hidden = YES;
    }
    
    - (void)applicationDidBecomeActive:(UIApplication *)application{
        self.window.hidden = NO;
    }
    

    Example :

    @implementation AppDelegate
    
    - (BOOL)application:(UIApplication *)application
        didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      [GeneratedPluginRegistrant registerWithRegistry:self];
      // Override point for customization after application launch.
      return [super application:application didFinishLaunchingWithOptions:launchOptions];
    }
    
    - (void)applicationWillResignActive:(UIApplication *)application{
        self.window.hidden = YES;
    }
    
    - (void)applicationDidBecomeActive:(UIApplication *)application{
        self.window.hidden = NO;
    }
    
    @end
    

    see this great article by Gulshan Yadav: https://mrgulshanyadav.medium.com/prevent-screenshot-and-video-recording-in-flutter-93839325d66c

    Login or Signup to reply.
  2. You can use screen_protector. and turn it on and off as below. it will avoid your app screen recording or taking screenshots

     void _preventScreenshotOn() async =>
          await ScreenProtector.preventScreenshotOn();
     void _preventScreenshotOff() async =>
          await ScreenProtector.preventScreenshotOff();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search