Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: disable screenshot capture for app

Tags:

I am making a Flutter app and I need to make sure the user is not able to capture screenshot of the app (any screen). Is there any way to achieve this in Flutter or do I need to write native code for both Android and IOS?

like image 476
codeinprogress Avatar asked Sep 13 '18 15:09

codeinprogress


People also ask

How do I turn off screenshots on Flutter app?

yaml file of your Flutter project and run pub get. Then add the below code inside the widget's initState() method for which you want to disable screenshot and screen recording. If you want to make your whole app screenshot disable just call securescreen() method (defined above) inside your main() function in main.

How do I stop an app from taking screenshots?

The Project Settings dialog box appears. From the left pane, expand the Native tab, and then select the Android Mobile/Tablet sub-tab. In the Miscellaneous section, enable the Disable Application Screenshot check box. Click Done.

How do I stop a website from taking screenshots?

There are several ways to protect your pictures: disable right-click protection, apply a watermark to your pictures, register your copyright, add a copyright notice, or enable hotlink protection.


2 Answers

  1. Locate your MainActivity class inside the embedded android project dir in your Flutter Project
  2. Add the following import to your main activity class: import android.view.WindowManager.LayoutParams;
  3. Add the following line to your MainActivity's onCreate method: getWindow().addFlags(LayoutParams.FLAG_SECURE);
like image 182
Lennon Jesus Avatar answered Sep 17 '22 19:09

Lennon Jesus


For Flutter2 project

Method 1 : using package flutter_windowmanager

Method 2 :

in Android with kotlin

Step 1 Open the file "mainActivity.kt" using the path

android\app\src\main\kotlin\com\example\auth_email\MainActivity.kt

Step 2 Import Library

import android.view.WindowManager.LayoutParams import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine 

Step 3 In main activity class

class MainActivity: FlutterActivity() {   override fun configureFlutterEngine(flutterEngine: FlutterEngine) {     window.addFlags(LayoutParams.FLAG_SECURE)     super.configureFlutterEngine(flutterEngine)   } } 

In iOS Swift : AppDelegate.swift file

import UIKit import Flutter  @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate {    override func application(     _ application: UIApplication,     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?   ) -> Bool {     GeneratedPluginRegistrant.register(with: self)     return super.application(application, didFinishLaunchingWithOptions: launchOptions)   }      // <Add>   override func applicationWillResignActive(     _ application: UIApplication   ) {     self.window.isHidden = true;   }   override func applicationDidBecomeActive(     _ application: UIApplication   ) {     self.window.isHidden = false;   }     } 
like image 39
Jay Kukadiya Avatar answered Sep 21 '22 19:09

Jay Kukadiya