Flutter: disable screenshot capture for app

后端 未结 6 1008
日久生厌
日久生厌 2020-12-14 10:48

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 nee

相关标签:
6条回答
  • 2020-12-14 11:19

    What worked for me was writing the below code in MainActivity.java file.

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

    and importing these packages!

    import android.view.WindowManager; 
    import android.view.WindowManager.LayoutParams;
    import android.os.Bundle; // required for onCreate parameter
    
    0 讨论(0)
  • 2020-12-14 11:24

    Screenshots can be prevented very easily by following below two steps.

    I am using VS code.

    Step 1 Open the file "mainActivity.kt" using the path android\app\src\main\kotlin\com\example\auth_email\MainActivity.kt

    Step 2 Add the two lines

    (a) import android.view.WindowManager.LayoutParams; 
    
    (b) getWindow().addFlags(LayoutParams.FLAG_SECURE); in MainActivity: FlutterActivity() section
    

    Restart the app

    enter image description here

    0 讨论(0)
  • 2020-12-14 11:26

    This works for iOS. In your Runner > AppDelegate.m:

    @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
    
    0 讨论(0)
  • 2020-12-14 11:37

    You could maybe listen for the screenshot keys on iOS and when the combination is being pressed blacken the screen.

    0 讨论(0)
  • 2020-12-14 11:41

    If you are using kotlin

    open MainActivity.kt

    Add below code at end of imports

    import android.view.WindowManager.LayoutParams
    

    Add below code at end of super.onCreate(savedInstanceState)

    window.addFlags(LayoutParams.FLAG_SECURE)
    

    Its done.

    0 讨论(0)
  • 2020-12-14 11:43
    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);
    0 讨论(0)
提交回复
热议问题