how to restrict users to take screen shots of the course app?
- the flutter app is targeting android platform.
- the app will be using PDF view and video courses.
how to restrict users to take screen shots of the course app?
In your MainActivity
class, inside the android project dir in your Flutter Project
Add the following import
to your MainActivity
class:
import android.view.WindowManager.LayoutParams;
Add the following line to your MainActivity's
onCreate method:
getWindow().addFlags(LayoutParams.FLAG_SECURE);
It will solve the problem you are facing, and restrict the OS from taking the screenshot.
The simplest to do that is by using the flutter_windowmanager plugin
First import its latest version in pubspec.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.
Future<void> secureScreen() async {
await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
}
@override
void initState() {
secureScreen();
super.initState();
}
If you want to make your whole app screenshot disable just call securescreen() method (defined above) inside your main() function in main.dart file.
option 2:
Write this below code in the 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