android prevent screenshot in activity

To prevent screenshots in an Android activity using Kotlin, you can follow these steps:

  1. Create a new Kotlin file and name it SecureActivity.kt.
  2. Define the SecureActivity class and extend it from AppCompatActivity.
  3. Override the onCreate method and set the window flags to prevent screenshots using the following code:
window.setFlags(
    WindowManager.LayoutParams.FLAG_SECURE,
    WindowManager.LayoutParams.FLAG_SECURE
)
  1. In your other activities, extend from SecureActivity instead of AppCompatActivity to inherit the screenshot prevention behavior.

By following these steps, you can prevent screenshots in an Android activity using Kotlin.