In flutter how to prevent screenshot to secure my app for android part in kotlin - flutter

In my flutter app, it supports the kotlin for android part. i can't find a code to prevent the screeenshot in app which is written in kotlin language. I searched over the google then i found the code that is written in java language but i require the kotlin code to prevent the screenshot.
package com.example.schoolbells
import io.flutter.embedding.android.FlutterActivity
import android.os.Bundle;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterEngine;
import android.view.WindowManager.LayoutParams;
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,WindowManager.LayoutParams.FLAG_SECURE);
}
}
getting this error in onCreate method
[ERROR] :Unresolved reference: WindowManagerkotlin(UNRESOLVED_REFERENCE)
I tried this code in kotlin but getting error.
Is there any other way to prevent screenshot in flutter?

Related

why this WebView widget is showing error in my flutter app

How to solve this. In flutter i have imported the import 'package:webview_flutter/webview_flutter.dart';
package but still the WebView is showing error :
The method 'WebView isn't defined for the type' Article PageState.:39

How do I use local auth and bar code scanner in the same flutter project?

I building a flutter app that scans bar codes and also uses biometric auth in it. The problem is for package local_auth
MainActivity.kt should be like
import io.flutter.embedding.android.FlutterFragmentActivity;
public class MainActivity extends FlutterFragmentActivity {
// ...
}
but for scaning bar codes MainActivity.kt should be like
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
else it don't work. How do I use them both in the same project?
Currently you have to replace FlutterActivity with FlutterFragmentActivity yourself in FlutterBarcodeScannerPlugin.java (like this).
So you would want to use a fork of the flutter_barcode_scanner plugin where FlutterFragmentActivity is used or you use some other barcode scanner plugin.

How do I use multiple main activities in flutter?

I am building a flutter app which has these two plugins 1) local_auth 2) flutter_bar_code and they both use different main activities , for local auth the MainActivity.kt is like
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity: FlutterFragmentActivity() {
}
and for flutter bar code scanner the MainActivity.tk is like
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
Flutter has a single MainActivity file. if you want to add more screen then please read doc and blogs here is one for you: Add Multiple screen

Disable screenshot in flutter

How to disable screenshot in flutter? I have Kotlin file instead of MainActivity.java file. Please suggest full code with path where I need to change for disable screenshot in my app.
package com.quotster.untitled
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
If you want to do that in Android only you can use flutter_windowmanager and add FLAG_SECURE.
await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);

Issue : Cant resolve symbol 'firebasemessaging'

I am using Firebase Cloud Messaging for getting notifications. I was getting proper notifications when my app was running but when my app was in background, I used to get this exception on arrival of the notification :
After some digging I got a solution for this where they performed the following changes :
My MyActivity.java :
package ......; /* Package Name*/
import android.os.Bundle;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
Application.java :
GeneratedPluginRegistrant.java
And I changed the 'android:name' of tag form "io.flutter.app.FlutterApplication" to ".Application" accordingly :
Now as you can see in the screenshots provided above ..... I am getting errors saying cannot revolves symbol 'Firebasemesseging' etc. (Same 'Cannot resolve' everywhere). Can anyone please help me to fix this error. I am a bit new to Flutter hence I am not sure how to solve this.
Thanks a lot in advance for the help.