问题描述
我使用 FLAG_SECURE
来避免使用 flutter_pdfview 包的屏幕截图。
该软件包适用于几乎所有设备上的 FLAG_SECURE
,但在 Oppo 设备上显示黑屏。
我试过了:
- 使用原生 Android 代码设置
FLAG_SECURE
- 使用 flutter_windowmanager 包
这是我在 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 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
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)