With the help of this thread I am able to prevent screenshots in my app but How can I use it only in a particular section of my app. It makes my whole app unshareable.
I have a section that shows notes to my premium members. I don't want the user to take screenshots of it.
My app has MainActivity in kotlin so when I copied the java code from thread mentioned my IDE converted it to Kotlin.
import android.os.Bundle
import android.view.WindowManager.LayoutParams
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE)
}
}