GithubHelp home page GithubHelp logo

prevent_screenshots's Introduction

Prevent Screenshots and Screen Recording

To learn how to prevent screenshots and screen recording in your project, follow these steps:

For Android

You don't need to do anything right now, just wait until the end, The idea is that we'll simply use the flutter_windowmanager package to achieve this for Android.

To add the package to your dependencies, run this command in the project terminal:
flutter pub add flutter_windowmanager
To understand, this code will enable the secure mode:
FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
And this code will disable the secure mode:
FlutterWindowManager.clearFlags(FlutterWindowManager.FLAG_SECURE);

For iOS

We will write some Swift native code to achieve this.

- In this repository, go to: ios/Runner/prevent.swift and copy everything.
- Then, open your project in Xcode and go to Runner to create a Swift file, for example, prevent.swift.
- Paste the code that you have copied.
- Add this line inside your ios/Runner/AppDelegate.swift:
ScreenRecordHandler.shared.configure()
- Your AppDelegate will look like this:
 import UIKit
 import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {

 // Prevent screenshots and recording
    ScreenRecordHandler.shared.configure()
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

Finishing

- In my repository, go to lib/code/utils/screen_record_shoot_handler.
- Do the same -> create a Dart file wherever you want inside the lib folder and put this code inside it.
- Call preventScreenRecord in initState and disposePreventScreenRecord in dispose like this:
final ScreenRecordHandlerChannel screenRecordHandlerChannel = ScreenRecordHandlerChannel();

@override
 void initState() {
   screenRecordHandlerChannel.preventScreenRecord();
   super.initState();
 }

 @override
 void dispose() {
   screenRecordHandlerChannel.disposePreventScreenRecord();
   super.dispose();
 }
Note: Test your app on a real device, not on an Android emulator or iOS simulator.

prevent_screenshots's People

Stargazers

 avatar

Watchers

Amr Hassan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.