android prevent screenshot in activity
To prevent screenshots in an Android activity using Kotlin, you can follow these steps:
- Create a new Kotlin file and name it
SecureActivity.kt
. - Define the
SecureActivity
class and extend it fromAppCompatActivity
. - 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
)
- In your other activities, extend from
SecureActivity
instead ofAppCompatActivity
to inherit the screenshot prevention behavior.
By following these steps, you can prevent screenshots in an Android activity using Kotlin.