1

I am currently developing an application in python with kivy. It works like a chat app and I want to integrate the same feature as for example snapchat does: detecting screenshots. I want my code to either detect if someone does a screenshot or completely prevent it. And yes, I know that these things can be bypassed by using another camera or something but thats not the point.

In Kivy there is no on_screenshot function, so you have to come up with something different. I've found ideas to detect whether a new file was saved in the screenshots folder but that not going to work when you choose another path. I want it directly in the app. I found the flag_secure attribute in java and tried implmementing it with pyjnius, which didn't work. I asked ChatGPT, who couldn't help either. It gave me this (not working) code.

from jnius import autoclass

PythonActivity = autoclass('org.kivy.android.PythonActivity')
activity = PythonActivity.mActivity

WindowManager = autoclass('android.view.WindowManager')
LayoutParams = autoclass('{}.LayoutParams'.format(WindowManager.__name__))
params = activity.getWindow().getAttributes()

LayoutParams.FLAG_SECURE = 0x00002000
params.flags |= LayoutParams.FLAG_SECURE
activity.getWindow().setAttributes(params)

Implementing real java code doesn't work in python with android either.

0 Answers0