Hi , I am using FLAG_SECURE to avoid screenshots
the package works good with FLAG_SECURE in all devices expect in oppo devices it display a black screen
i use a native code in android to set FLAG_SECURE
i have tryed to use flutter_windowmanager package but i have the same black screen problem in oppo devices only
This my native code in MainActivity.kt
`
package com.online.education.mostafa.elsheikh
import android.os.Bundle
import android.util.Log
import android.view.SurfaceView
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
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)
if (!setSecureSurfaceView()) {
Log.e("MainActivity", "Could not secure the MainActivity!")
// React as appropriate.
}
}
private fun setSecureSurfaceView(): Boolean {
val content = findViewById(android.R.id.content)
if (!isNonEmptyContainer(content)) {
return false
}
val splashView = content.getChildAt(0)
if (!isNonEmptyContainer(splashView)) {
return false
}
val flutterView = (splashView as ViewGroup).getChildAt(0)
if (!isNonEmptyContainer(flutterView)) {
return false
}
val surfaceView = (flutterView as ViewGroup).getChildAt(0)
if (surfaceView !is SurfaceView) {
return false
}
surfaceView.setSecure(true)
this.window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
return true
}
private fun isNonEmptyContainer(view: View): Boolean {
if (view !is ViewGroup) {
return false
}
if (view.childCount < 1) {
return false
}
return true
}
}
`
Any help please ??
Hi , I am using FLAG_SECURE to avoid screenshots the package works good with FLAG_SECURE in all devices expect in oppo devices it display a black screen i use a native code in android to set FLAG_SECURE i have tryed to use flutter_windowmanager package but i have the same black screen problem in oppo devices only
This my native code in MainActivity.kt ` package com.online.education.mostafa.elsheikh import android.os.Bundle import android.util.Log import android.view.SurfaceView import android.view.View import android.view.ViewGroup import android.view.WindowManager 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) if (!setSecureSurfaceView()) { Log.e("MainActivity", "Could not secure the MainActivity!") // React as appropriate. } }
private fun setSecureSurfaceView(): Boolean { val content = findViewById(android.R.id.content)
if (!isNonEmptyContainer(content)) {
return false
}
val splashView = content.getChildAt(0)
if (!isNonEmptyContainer(splashView)) {
return false
}
val flutterView = (splashView as ViewGroup).getChildAt(0)
if (!isNonEmptyContainer(flutterView)) {
return false
}
val surfaceView = (flutterView as ViewGroup).getChildAt(0)
if (surfaceView !is SurfaceView) {
return false
}
surfaceView.setSecure(true)
this.window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
return true
}
private fun isNonEmptyContainer(view: View): Boolean { if (view !is ViewGroup) { return false } if (view.childCount < 1) { return false } return true } } ` Any help please ??